Example #1
0
 protected function _initCache()
 {
     // Get configurations
     $file = APPLICATION_PATH . '/application/settings/cache.php';
     // @todo cache config in database
     if (file_exists($file)) {
         // Manual config
         $options = (include $file);
     } else {
         if (is_writable(APPLICATION_PATH . '/temporary/cache') || !@is_dir(APPLICATION_PATH . '/temporary/cache') && @mkdir(APPLICATION_PATH . '/temporary/cache', 0777, true)) {
             // Auto default config
             $options = array('default_backend' => 'File', 'frontend' => array('core' => array('automatic_serialization' => true, 'cache_id_prefix' => 'Engine4_', 'lifetime' => '300', 'caching' => true)), 'backend' => array('File' => array('cache_dir' => APPLICATION_PATH . '/temporary/cache')));
         } else {
             // Failure
             return null;
         }
     }
     // Create cache
     $frontend = key($options['frontend']);
     $backend = key($options['backend']);
     Engine_Cache::setConfig($options);
     $cache = Engine_Cache::factory($frontend, $backend);
     // Disable caching in development mode
     if (APPLICATION_ENV == 'development') {
         $cache->setOption('caching', false);
     }
     // Save in registry
     Zend_Registry::set('Zend_Cache', $cache);
     // Use cache helper?
     Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-1, new Engine_Controller_Action_Helper_Cache());
     // Add cache to database
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     // Save in bootstrap
     return $cache;
 }