From 780b77af58b0a00e062b7f9b12423a2dc181fd8c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 27 Sep 2013 17:45:20 +0200 Subject: [PATCH] [HttpKernel] made the cache key generation configurable for the default HttpCache store --- .../Component/HttpKernel/HttpCache/Store.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Store.php b/src/Symfony/Component/HttpKernel/HttpCache/Store.php index acddb82652..8e4234d126 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Store.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Store.php @@ -364,6 +364,25 @@ class Store implements StoreInterface return $this->root.DIRECTORY_SEPARATOR.substr($key, 0, 2).DIRECTORY_SEPARATOR.substr($key, 2, 2).DIRECTORY_SEPARATOR.substr($key, 4, 2).DIRECTORY_SEPARATOR.substr($key, 6); } + /** + * Generates a cache key for the given Request. + * + * This method should return a key that must only depend on a + * normalized version of the request URI. + * + * If the same URI can have more than one representation, based on some + * 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) + { + return 'md'.hash('sha256', $request->getUri()); + } + /** * Returns a cache key for the given Request. * @@ -377,7 +396,7 @@ class Store implements StoreInterface return $this->keyCache[$request]; } - return $this->keyCache[$request] = 'md'.hash('sha256', $request->getUri()); + return $this->keyCache[$request] = $this->generateCacheKey($request); } /**