merged branch lolautruche/httpCacheStoreExtendable (PR #6016)
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #6016). Commits ------- 9b0cad4 Added HttpCache\Store::generateContentDigest() + changed visibility Discussion ---------- Added HttpCache\Store::generateContentDigest() + changed $root visibility Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - License of the code: MIT Documentation PR: - ## Description This PR adds 2 small changes in base `HttpCache\Store`: 1. Adds `generateContentDigest()` protected method, allowing to easily override the default behavior for special cases. 2. Change `$root` visibility to *protected* to let descendant access it. This allows special implementations of HttpCache when storing specific cache files in a different place is needed. ## Example An example of implementation can be found [in eZ Publish 5 source code](https://github.com/ezsystems/ezp-next/blob/master/eZ/Publish/Core/MVC/Symfony/Cache/Http/LocationAwareStore.php). In this example, eZ Publish content cache entities are stored under a different folder than regular cache entities in order to ease cache purge based on a content location. ## Testing No unit tests were added since the behavior didn't change and the new method is protected. PS : It would be nice to have this in 2.1 branch as well 😃
This commit is contained in:
commit
9a2edb9a63
@ -24,7 +24,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
*/
|
*/
|
||||||
class Store implements StoreInterface
|
class Store implements StoreInterface
|
||||||
{
|
{
|
||||||
private $root;
|
protected $root;
|
||||||
private $keyCache;
|
private $keyCache;
|
||||||
private $locks;
|
private $locks;
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ class Store implements StoreInterface
|
|||||||
|
|
||||||
// write the response body to the entity store if this is the original response
|
// write the response body to the entity store if this is the original response
|
||||||
if (!$response->headers->has('X-Content-Digest')) {
|
if (!$response->headers->has('X-Content-Digest')) {
|
||||||
$digest = 'en'.sha1($response->getContent());
|
$digest = $this->generateContentDigest($response);
|
||||||
|
|
||||||
if (false === $this->save($digest, $response->getContent())) {
|
if (false === $this->save($digest, $response->getContent())) {
|
||||||
throw new \RuntimeException('Unable to store the entity.');
|
throw new \RuntimeException('Unable to store the entity.');
|
||||||
@ -192,6 +192,18 @@ class Store implements StoreInterface
|
|||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns content digest for $response.
|
||||||
|
*
|
||||||
|
* @param Response $response
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function generateContentDigest(Response $response)
|
||||||
|
{
|
||||||
|
return 'en'.sha1($response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates all cache entries that match the request.
|
* Invalidates all cache entries that match the request.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user