如何在Symfony 2中进行缓存? [英] How to cache in Symfony 2?
本文介绍了如何在Symfony 2中进行缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用Symfony 2的缓存系统缓存一些特定于应用程序的数据,以便我可以运行cache:clear
清除它.所有缓存都依赖于app/cache
,但是实际上如何缓存数据?
I need to cache some application specific data using Symfony 2's caching system so that I can run cache:clear
to clear it. All the cache relies under app/cache
but how do I actually go about caching data?
http://symfony.com/doc/current/cookbook/index.html
我看到的唯一主题是有关使用Varnish进行HTML缓存的
The only topic I see is about HTML caching with Varnish.
推荐答案
如果您正在使用Doctrine,则只需使用这些缓存类即可.
If you are using Doctrine already just use those cache classes.
向config.yml
添加服务:
services:
cache:
class: Doctrine\Common\Cache\ApcCache
并在您的控制器中使用它:
And use it in your controller:
if ($fooString = $this->get('cache')->fetch('foo')) {
$foo = unserialize($fooString);
} else {
// do the work
$this->get('cache')->save('foo', serialize($foo));
}
这篇关于如何在Symfony 2中进行缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文