CakePHP:多域名缓存

来源:互联网 发布:json 空值 编辑:程序博客网 时间:2024/04/29 05:22

如果你有多个域名(常见的是多国家)映射到同一份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

原创粉丝点击