首页 > symfony2怎么使用文件缓存?

symfony2怎么使用文件缓存?

网站主菜单数组,获取比较复杂,而且每个页面都要调用,想获取一次后缓存起来,有什么比较简单的方法?

不用框架的话,会像下面这样把菜单存在文本里

if (is_file('menu.txt')) {
    $mainMenuArr = unserialize(file_get_contnets('menu.txt'));
} else {
    $mainMenuArr = $this->getMainMenu();
    file_put_contents('menu.txt', serialize($mainMenuArr ));
}

而symfony2,看文档里关于缓存的部分,只有HTTP Cache,这些对于小项目不怎么适用 http://symfony.com/doc/current/book/http_cache.html


基本缓存就这样吧 memcached 或者Nosql数据库。

文件缓存的话,可以直接存html文件~


用Doctrine的Cache就可以,你是看文档得出的只有那些内存缓存的结论的吧?文档其实不全 :)

看源代码吧,什么都有: https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache

如FileCache: https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/FileCache.php

【热门文章】
【热门文章】