/** * 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); }
/** * 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); }
protected function storeSimpleEntry($path = null, $headers = array()) { if (null === $path) { $path = '/test'; } $this->request = Request::create($path, 'get', array(), array(), array(), $headers); $this->response = new Response('test', 200, array('Cache-Control' => 'max-age=420')); return $this->store->write($this->request, $this->response); }
/** * @param string $root * @param string[] $cacheCookies */ public function __construct($root, array $cacheCookies) { $this->cacheCookies = $cacheCookies; parent::__construct($root); }