Мой совет - создайте метод инициализации в Bootstrap.php с префиксом "_init". Например:
/**
*
* @return Zend_Cache_Manager
*/
public function _initCache()
{
$cacheManager = new Zend_Cache_Manager();
$frontendOptions = array(
'lifetime' => 7200, // cache lifetime of 2 hours
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => APPLICATION_PATH . '/cache/zend_cache'
);
$coreCache = Zend_Cache::factory(
'Core',
'File',
$frontendOptions,
$backendOptions
);
$cacheManager->setCache('coreCache', $coreCache);
$pageCache = Zend_Cache::factory(
'Page',
'File',
$frontendOptions,
$backendOptions
);
$cacheManager->setCache('pageCache', $pageCache);
Zend_Registry::set('cacheMan', $cacheManager);
return $cacheManager;
}
Таким образом, вы создали и внедрили в свой менеджер кэша те кэши, которые вам нужны в вашем приложении.
Теперь вы можете использовать этот объект кэша, где вы хотите использовать.
Например, в вашем контроллере или где-либо еще:
/**
*
* @return boolean |SimplePie
*/
public function getDayPosts()
{
$cacheManager = Zend_Registry::get('cacheMan');
$cache = $cacheManager->getCache('coreCache');
$cacheID = 'getDayPosts';
if (false === ($blog = $cache->load($cacheID))) {
$blog = Blog::find(array('order' => 'rand()', 'limit' => 1));
$cache->save($blog, $cacheID);
}
// do what you want to do with the daya you fetched.
}