From 807755f00212dc09b9ea49080c5b844ccc6548c6 Mon Sep 17 00:00:00 2001 From: Will Morgan Date: Fri, 2 May 2014 17:51:43 +0100 Subject: [PATCH] FIX TemplateManifest prevent cache collision --- core/manifest/TemplateManifest.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/manifest/TemplateManifest.php b/core/manifest/TemplateManifest.php index 371cb0371..5e9f4a10c 100644 --- a/core/manifest/TemplateManifest.php +++ b/core/manifest/TemplateManifest.php @@ -38,11 +38,35 @@ class SS_TemplateManifest { $cacheClass = defined('SS_MANIFESTCACHE') ? SS_MANIFESTCACHE : 'ManifestCache_File'; $this->cache = new $cacheClass('templatemanifest'.($includeTests ? '_tests' : '')); - $this->cacheKey = 'manifest'; + $this->cacheKey = $this->getCacheKey($includeTests); $this->forceRegen = $forceRegen; } + /** + * @return string + */ + public function getBase() { + return $this->base; + } + + /** + * Generate a unique cache key to avoid manifest cache collisions. + * We compartmentalise based on the base path, the given project, and whether + * or not we intend to include tests. + * @param boolean $includeTests + * @return string + */ + public function getCacheKey($includeTests = false) { + return sha1(sprintf( + "manifest-%s-%s-%s", + $this->base, + $this->project, + (int) $includeTests // cast true to 1, false to 0 + ) + ); + } + /** * Returns a map of all template information. The map is in the following * format: