网站主菜单数组,获取比较复杂,而且每个页面都要调用,想获取一次后缓存起来,有什么比较简单的方法?
不用框架的话,会像下面这样把菜单存在文本里
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文件~