Zend_Cache
是否可以有两个不同的缓存实例?
例如,如果我想要一组文件永久存储,除非我删除它们,而另一组文件每分钟就会失效 - 我可以这样做吗?
Everywhere I look我总是看到只使用一种前端和后端配置。
谢谢!
最佳答案
您只需创建两个不同的 Zend_Cache 实例并将它们粘贴到方便的地方。我做了一次类似的事情,在 boostrap 中实例化缓存实例,然后将它们粘贴到注册表中,如下所示:
protected function _initCache(){
$this->bootstrap('config');
$config = Zend_Registry::get('config')->myapp->cache;
$cache = Zend_Cache::factory(
$config->frontend->name,
$config->backend->name,
$config->frontend->opts->toArray(),
$config->backend->opts->toArray()
);
Zend_Registry::set('cache',$cache);
return $cache;
}
protected function _initUserCache(){
$this->bootstrap('config');
$config = Zend_Registry::get('config')->myapp->othercache;
$cache = Zend_Cache::factory(
$config->frontend->name,
$config->backend->name,
$config->frontend->opts->toArray(),
$config->backend->opts->toArray()
);
Zend_Registry::set('othercache',$cache);
return $cache;
}
因此,Zend_Cache 的设计实际上并没有限制您可以拥有的不同缓存的数量。您可以独立配置它们,使用您喜欢的任何前端和后端。
关于zend-framework - 不止一个 Zend_Cache 配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10464855/