/**
  * Invalidate the cache entries associated with any of the given list of tags.
  *
  * @param string[] $tags
  */
 public function invalidateTags(array $tags)
 {
     $digests = $this->tagStorage->getCacheIds($tags);
     foreach ($digests as $cacheDigest) {
         $cachePath = $this->cacheStorage->getPath($cacheDigest);
         $this->filesystem->remove($cachePath);
     }
     // remove the tag directory
     $this->tagStorage->removeTags($tags);
 }
示例#2
0
 public function testRemovesEntriesForKeyWithPurge()
 {
     $request = Request::create('/foo');
     $this->store->write($request, new Response('foo'));
     $metadata = $this->getStoreMetadata($request);
     $this->assertNotEmpty($metadata);
     $this->assertTrue($this->store->purge('/foo'));
     $this->assertEmpty($this->getStoreMetadata($request));
     // cached content should be kept after purging
     $path = $this->store->getPath($metadata[0][1]['x-content-digest'][0]);
     $this->assertTrue(is_file($path));
     $this->assertFalse($this->store->purge('/bar'));
 }
 /**
  * Returns the right path where cache is being stored.
  * Will detect if $key is eZ Publish specific.
  *
  * @param string $key
  *
  * @return string
  */
 public function getPath($key)
 {
     if (strpos($key, static::LOCATION_CACHE_DIR) === false) {
         return parent::getPath($key);
     }
     $prefix = '';
     if (($pos = strrpos($key, '/')) !== false) {
         $prefix = substr($key, 0, $pos) . DIRECTORY_SEPARATOR;
         $key = substr($key, $pos + 1);
         list($locationCacheDir, $locationId) = explode('/', $prefix);
         unset($locationCacheDir);
         // If cache purge is in progress, serve stale cache instead of regular cache.
         // We first check for a global cache purge, then for the current location.
         foreach (array($this->getLocationCacheLockName(), $this->getLocationCacheLockName($locationId)) as $cacheLockFile) {
             if (is_file($cacheLockFile)) {
                 if (function_exists('posix_kill')) {
                     // Check if purge process is still running. If not, remove the lock file to unblock future cache purge
                     if (!posix_kill(file_get_contents($cacheLockFile), 0)) {
                         $fs = $this->getFilesystem();
                         $fs->remove(array($cacheLockFile, $this->getLocationCacheDir($locationId)));
                         goto returnCachePath;
                     }
                 }
                 $prefix = str_replace(static::LOCATION_CACHE_DIR, static::LOCATION_STALE_CACHE_DIR, $prefix);
             }
         }
     }
     returnCachePath:
     return $this->root . DIRECTORY_SEPARATOR . $prefix . substr($key, 0, 2) . DIRECTORY_SEPARATOR . substr($key, 2, 2) . DIRECTORY_SEPARATOR . substr($key, 4, 2) . DIRECTORY_SEPARATOR . substr($key, 6);
 }