_frontendOptions = $params; return $this; } /** * set the options for backend * * @param array $params * @return Zend_Application_Resource_Cache */ public function setBackend(array $params) { if(!isset($params[self::OPTION_CLASS])) { throw new Zend_Application_Resource_Exception("backend class has not been defined"); } $this->_backendOptions = $params; } /** * retrieve the class name used as frontend * * @return string */ public function getFrontendClassName() { return $this->_frontendOptions[self::OPTION_CLASS]; } /** * retrieve the class name used as backend * * @return string */ public function getBackendClassName() { return $this->_backendOptions[self::OPTION_CLASS]; } /** * Defined by Zend_Application_Resource_Resource * * @return Zend_Cache_Core */ public function init() { if ($this->_frontendOptions == null || $this->_backendOptions == null) { throw new Zend_Application_Resource_Exception("frontend and backend class names must be defined"); } $frontendOptions = $backendOptions = array(); if (isset($this->_frontendOptions[self::OPTION_PARAMS]) && is_array($this->_frontendOptions[self::OPTION_PARAMS])) { $frontendOptions = $this->_frontendOptions[self::OPTION_PARAMS]; } if (isset($this->_backendOptions[self::OPTION_PARAMS]) && is_array($this->_backendOptions[self::OPTION_PARAMS])) { $backendOptions = $this->_backendOptions[self::OPTION_PARAMS]; } $this->_cache = Zend_Cache::factory($this->getFrontendClassName(), $this->getBackendClassName(), $frontendOptions, $backendOptions); if ($this->_shareToZendObjects) { $this->_shareToZendObjects(); } return $this->_cache; } /** * Returns the cache object * * @return Zend_Cache_Core */ public function getCache() { return $this->_cache; } /** * Wether to share the cache object * to all Zend objects that accept one statically * * @return Zend_Application_Resource_Cache */ public function setShareToZendObjects() { $this->_shareToZendObjects = true; return $this; } /** * Shares the cache instance * to all Zend objects that accept one statically * * @return Zend_Application_Resource_Cache */ protected function _shareToZendObjects() { Zend_Paginator::setCache($this->_cache); Zend_Db_Table::setDefaultMetadataCache($this->_cache); Zend_Date::setOptions(array('cache'=>$this->_cache)); Zend_Translate::setCache($this->_cache); Zend_Locale::setCache($this->_cache); return $this; } }