public function getPath($key)
{
if (strpos($key, static::LOCATION_CACHE_DIR) === false) {
return parent::getPath($key);
}
$prefix = '';
if (($pos = strrpos($key, DIRECTORY_SEPARATOR)) !== false) {
$prefix = substr($key, 0, $pos) . DIRECTORY_SEPARATOR;
$key = substr($key, $pos + 1);
list($locationCacheDir, $locationId) = explode(DIRECTORY_SEPARATOR, $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);
}