My advice is to create an initialization method in Bootstrap.php with the prefix "_init". for exaple:
/** * * @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; }
So you created and introduced your cache manager with the caches you need in your application. Now you can use this cache object that you want to use. For example, in your controller or somewhere else:
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); }
source share