Merge pull request #1003 from dereuromark/2.3-cache-prefixes

cache prefix for view cache to avoid collisions with domains/languages
This commit is contained in:
Mark 2012-12-17 00:46:08 -08:00
commit 8febb71b67
4 changed files with 30 additions and 2 deletions

View file

@ -129,6 +129,16 @@
*/
//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
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.

View file

@ -129,6 +129,16 @@
*/
//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
* 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();
if ($path == '/') {
if ($path === '/') {
$path = 'home';
}
$prefix = Configure::read('Cache.viewPrefix');
if ($prefix) {
$path = $prefix . '_' . $path;
}
$path = strtolower(Inflector::slug($path));
$filename = CACHE . 'views' . DS . $path . '.php';

View file

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