Skip to content

Commit

Permalink
cache prefix for view cache to avoid collisions with domains/languages
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Dec 11, 2012
1 parent 6bfbce1 commit 32f2426
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/Config/core.php
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions lib/Cake/Console/Templates/skel/Config/core.php
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion lib/Cake/Routing/Filter/CacheDispatcher.php
Expand Up @@ -42,9 +42,13 @@ public function beforeDispatch(CakeEvent $event) {
}

$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';
Expand Down
6 changes: 5 additions & 1 deletion lib/Cake/View/Helper/CacheHelper.php
Expand Up @@ -278,9 +278,13 @@ protected function _writeFile($content, $timestamp, $useCallbacks = false) {
$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)) {
Expand Down

0 comments on commit 32f2426

Please sign in to comment.