是否有可能爲Zend_Cache
有兩個不同的緩存實例?例如,如果我想擁有一組永久存儲的文件,除非我將它們刪除,而另一組文件每分鐘都會失效 - 我可以這樣做嗎?多個Zend_Cache配置?
Everywhere I look我總是看到只有一個使用的前端和後端配置。
謝謝!
是否有可能爲Zend_Cache
有兩個不同的緩存實例?例如,如果我想擁有一組永久存儲的文件,除非我將它們刪除,而另一組文件每分鐘都會失效 - 我可以這樣做嗎?多個Zend_Cache配置?
Everywhere I look我總是看到只有一個使用的前端和後端配置。
謝謝!
您只需創建Zend_Cache的兩個不同實例並將它們粘在某個方便的地方。我做了這樣的事情一次,實例緩存實例中的自舉,只是把它們插在註冊表中,就像這樣:
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是設計限制不同緩存的數量你可以有。你可以獨立地配置它們,使用你喜歡的任何前端和後端。
可以使用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中以合適的詞彙(自舉)
protected function _initCache()
{
Zend_Registry::set('Zend_Caches', $this->bootstrap('cachemanager')
->getPluginResource('cachemanager')
->getCacheManager());
}
用法(無處不在)
Zend_Registry::get('Zend_Caches')->foo
你不能使用通過'Zend_Cache_Manager不同'cacheTemplate' :: setCacheTemplate()',而比使用不同的'Zend_Cache'?不知道我完全遵循你的邏輯。 – tcole