您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

symfony2怎么使用文件缓存?

2024/4/25 21:14:51发布5次查看
网站主菜单数组,获取比较复杂,而且每个页面都要调用,想获取一次后缓存起来,有什么比较简单的方法?
不用框架的话,会像下面这样把菜单存在文本里
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
回复内容: 网站主菜单数组,获取比较复杂,而且每个页面都要调用,想获取一次后缓存起来,有什么比较简单的方法?
不用框架的话,会像下面这样把菜单存在文本里
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
用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
基本缓存就这样吧 memcached 或者nosql数据库。
文件缓存的话,可以直接存html文件~
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录