Zend framework 多个Zend_缓存配置?
对于Zend framework 多个Zend_缓存配置?,zend-framework,zend-cache,Zend Framework,Zend Cache,对于Zend_缓存,是否可能有两个不同的缓存实例? 例如,如果我想有一组文件永久存储,除非我删除它们,还有另一组文件每分钟都会失效,我可以这样做吗 我总是看到只使用一个前端和后端配置 谢谢 您只需创建两个不同的Zend_缓存实例,并将它们粘贴到方便的地方。我曾经做过类似的事情,在boostrap中实例化缓存实例,然后将它们粘贴到注册表中,如下所示: protected function _initCache(){ $this->bootstrap('config'); $c
Zend_缓存
,是否可能有两个不同的缓存实例?
例如,如果我想有一组文件永久存储,除非我删除它们,还有另一组文件每分钟都会失效,我可以这样做吗
我总是看到只使用一个前端和后端配置
谢谢 您只需创建两个不同的Zend_缓存实例,并将它们粘贴到方便的地方。我曾经做过类似的事情,在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_缓存的设计并没有限制不同缓存的数量。您可以使用您喜欢的前端和后端对它们进行独立配置。您可以使用cachemanager资源,例如:
resources.cachemanager.foo.frontend.name = Core
resources.cachemanager.foo.frontend.options.lifetime = 300
resources.cachemanager.foo.frontend.options.automatic_serialization = true
resources.cachemanager.foo.frontend.options.cache_id_prefix = some_prefix
resources.cachemanager.foo.backend.name = Memcached
resources.cachemanager.foo.backend.options.lifetime = 300
“foo”是缓存键,您可以指定任意数量的缓存键
接下来,我将cachemanager放入Zend_注册表(在引导程序中)
用法(无处不在)
您不能通过
Zend_Cache_Manager::setCacheTemplate()
使用不同的cacheTemplate
,而不是使用不同的Zend_Cache
?我不确定我是否完全遵循你的逻辑。
protected function _initCache()
{
Zend_Registry::set('Zend_Caches', $this->bootstrap('cachemanager')
->getPluginResource('cachemanager')
->getCacheManager());
}
Zend_Registry::get('Zend_Caches')->foo