Permalink
Browse files

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

  • Loading branch information...
1 parent 6bfbce1 commit 32f2426001893873265cc2c47ac4afc1735e095c @dereuromark dereuromark committed Dec 11, 2012
View
@@ -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.
@@ -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.
@@ -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';
@@ -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)) {

0 comments on commit 32f2426

Please sign in to comment.