如果你有多个域名(常见的是多国家)映射到同一份CakePHP代码上,而视图层采用不同的theme。
这个时候由于所有域名使用共同的app/tmp/cache/view下面的视图缓存文件,将出现彼此覆盖。
解决方法是对cake的dispatcher中的cached方法重新实现,在视图缓存文件名称前加上域名前缀如cn_slug.php。
// hack for multi domain cache
// $path = strtolower(Inflector::slug($path));
$path = strtolower(env('HTTP_HOST')) . '_' .strtolower(Inflector::slug($path));
然后重新实现cache helper中的__writeFile方法:
$cache = strtolower(Inflector::slug($path));
if (empty($cache)) {
return;
}
$cache = strtolower(env('HTTP_HOST')) . '_'.$cache;
$cache = $cache . '.php';
$file = '<!--cachetime:' . $cacheTime . '--><?php';
regards,
iefreer
本文介绍了一种解决多域名映射至同一份CakePHP代码时视图缓存冲突的方法,通过修改dispatcher中的cached方法及cachehelper中的__writeFile方法,为每个域名生成带有特定前缀的缓存文件。
323

被折叠的 条评论
为什么被折叠?



