private $locks;
/**
- * Constructor.
- *
* @param string $root The path to the cache directory
*
* @throws \RuntimeException
/**
* Tries to lock the cache for a given Request, without blocking.
*
- * @param Request $request A Request instance
- *
* @return bool|string true if the lock is acquired, the path to the current lock otherwise
*/
public function lock(Request $request)
/**
* Releases the lock for the given Request.
*
- * @param Request $request A Request instance
- *
* @return bool False if the lock file does not exist or cannot be unlocked, true otherwise
*/
public function unlock(Request $request)
/**
* Locates a cached Response for the Request provided.
*
- * @param Request $request A Request instance
- *
* @return Response|null A Response instance, or null if no cache entry was found
*/
public function lookup(Request $request)
return;
}
- list($req, $headers) = $match;
+ $headers = $match[1];
if (file_exists($body = $this->getPath($headers['x-content-digest'][0]))) {
return $this->restoreResponse($headers, $body);
}
* Existing entries are read and any that match the response are removed. This
* method calls write with the new list of cache entries.
*
- * @param Request $request A Request instance
- * @param Response $response A Response instance
- *
* @return string The key under which the response is stored
*
* @throws \RuntimeException
$entry[1]['vary'] = array('');
}
- if ($vary != $entry[1]['vary'][0] || !$this->requestsMatch($vary, $entry[0], $storedEnv)) {
+ if ($entry[1]['vary'][0] != $vary || !$this->requestsMatch($vary, $entry[0], $storedEnv)) {
$entries[] = $entry;
}
}
/**
* Returns content digest for $response.
*
- * @param Response $response
- *
* @return string
*/
protected function generateContentDigest(Response $response)
/**
* Invalidates all cache entries that match the request.
*
- * @param Request $request A Request instance
- *
* @throws \RuntimeException
*/
public function invalidate(Request $request)
$tmpFile = tempnam(dirname($path), basename($path));
if (false === $fp = @fopen($tmpFile, 'wb')) {
+ @unlink($tmpFile);
+
return false;
}
@fwrite($fp, $data);
@fclose($fp);
if ($data != file_get_contents($tmpFile)) {
+ @unlink($tmpFile);
+
return false;
}
if (false === @rename($tmpFile, $path)) {
+ @unlink($tmpFile);
+
return false;
}
}
* headers, use a Vary header to indicate them, and each representation will
* be stored independently under the same cache key.
*
- * @param Request $request A Request instance
- *
* @return string A key for the given Request
*/
protected function generateCacheKey(Request $request)
/**
* Returns a cache key for the given Request.
*
- * @param Request $request A Request instance
- *
* @return string A key for the given Request
*/
private function getCacheKey(Request $request)
/**
* Persists the Request HTTP headers.
*
- * @param Request $request A Request instance
- *
* @return array An array of HTTP headers
*/
private function persistRequest(Request $request)
/**
* Persists the Response HTTP headers.
*
- * @param Response $response A Response instance
- *
* @return array An array of HTTP headers
*/
private function persistResponse(Response $response)