예제 #1
0
 /**
  * @dataProvider provideAdaptiveTTL
  * @covers WANObjectCache::adaptiveTTL()
  * @param float|int $ago
  * @param int $maxTTL
  * @param int $minTTL
  * @param float $factor
  * @param int $adaptiveTTL
  */
 public function testAdaptiveTTL($ago, $maxTTL, $minTTL, $factor, $adaptiveTTL)
 {
     $mtime = $ago ? time() - $ago : $ago;
     $margin = 5;
     $ttl = $this->cache->adaptiveTTL($mtime, $maxTTL, $minTTL, $factor);
     $this->assertGreaterThanOrEqual($adaptiveTTL - $margin, $ttl);
     $this->assertLessThanOrEqual($adaptiveTTL + $margin, $ttl);
     $ttl = $this->cache->adaptiveTTL((string) $mtime, $maxTTL, $minTTL, $factor);
     $this->assertGreaterThanOrEqual($adaptiveTTL - $margin, $ttl);
     $this->assertLessThanOrEqual($adaptiveTTL + $margin, $ttl);
 }
예제 #2
0
 /**
  * Set the cached stat info for a file path.
  * Negatives (404s) are not cached. By not caching negatives, we can skip cache
  * salting for the case when a file is created at a path were there was none before.
  *
  * @param string $path Storage path
  * @param array $val Stat information to cache
  */
 protected final function setFileCache($path, array $val)
 {
     $path = FileBackend::normalizeStoragePath($path);
     if ($path === null) {
         return;
         // invalid storage path
     }
     $mtime = ConvertibleTimestamp::convert(TS_UNIX, $val['mtime']);
     $ttl = $this->memCache->adaptiveTTL($mtime, 7 * 86400, 300, 0.1);
     $key = $this->fileCacheKey($path);
     // Set the cache unless it is currently salted.
     $this->memCache->set($key, $val, $ttl);
 }