cache prefix for view cache to avoid collisions with domains/languages

This commit is contained in:
euromark 2012-12-11 12:54:16 +01:00
parent 6bfbce128f
commit 32f2426001
4 changed files with 30 additions and 2 deletions

View file

@ -129,6 +129,16 @@
*/ */
//Configure::write('Cache.check', true); //Configure::write('Cache.check', true);
/**
* Enable cache view prefixes.
*
* If set it will be prepended to the cache name for view file caching. This is
* helpful if you deploy the same application via multiple subdomains and languages,
* for instance. Each version can then have its own view cache namespace.
* Note: The final cache file name will then be `prefix_cachefilename`.
*/
//Configure::write('Cache.viewPrefix', 'prefix');
/** /**
* Defines the default error type when using the log() function. Used for * Defines the default error type when using the log() function. Used for
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG. * differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.

View file

@ -129,6 +129,16 @@
*/ */
//Configure::write('Cache.check', true); //Configure::write('Cache.check', true);
/**
* Enable cache view prefixes.
*
* If set it will be prepended to the cache name for view file caching. This is
* helpful if you deploy the same application via multiple subdomains and languages,
* for instance. Each version can then have its own view cache namespace.
* Note: The final cache file name will then be `prefix_cachefilename`.
*/
//Configure::write('Cache.viewPrefix', 'prefix');
/** /**
* Defines the default error type when using the log() function. Used for * Defines the default error type when using the log() function. Used for
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG. * differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.

View file

@ -42,9 +42,13 @@ class CacheDispatcher extends DispatcherFilter {
} }
$path = $event->data['request']->here(); $path = $event->data['request']->here();
if ($path == '/') { if ($path === '/') {
$path = 'home'; $path = 'home';
} }
$prefix = Configure::read('Cache.viewPrefix');
if ($prefix) {
$path = $prefix . '_' . $path;
}
$path = strtolower(Inflector::slug($path)); $path = strtolower(Inflector::slug($path));
$filename = CACHE . 'views' . DS . $path . '.php'; $filename = CACHE . 'views' . DS . $path . '.php';

View file

@ -278,9 +278,13 @@ class CacheHelper extends AppHelper {
$cacheTime = strtotime($timestamp, $now); $cacheTime = strtotime($timestamp, $now);
} }
$path = $this->request->here(); $path = $this->request->here();
if ($path == '/') { if ($path === '/') {
$path = 'home'; $path = 'home';
} }
$prefix = Configure::read('Cache.viewPrefix');
if ($prefix) {
$path = $prefix . '_' . $path;
}
$cache = strtolower(Inflector::slug($path)); $cache = strtolower(Inflector::slug($path));
if (empty($cache)) { if (empty($cache)) {