/** * Sets the translation cache * * @return void */ protected function _setCache() { $options = $this->getOptions(); // Disable cache? If not defined, cache will be active if (isset($options['cache']['active']) && !$options['cache']['active']) { // Explicitly remove cache, in case it was set before Zend_Translate::removeCache(); return; } // Get the cache using the config settings as input $this->_bootstrap->bootstrap('CacheManager'); $manager = $this->_bootstrap->getResource('CacheManager'); $cache = $manager->getCache('translate'); // Write caching errors to log file (if activated in the config) $this->_bootstrap->bootstrap('Log'); $logger = $this->_bootstrap->getResource('Log'); $cache->setOption('logger', $logger); Zend_Translate::setCache($cache); }
public function testTestingCacheHandling() { require_once 'Zend/Cache.php'; $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/_files/')); Zend_Translate::setCache($cache); $cache = Zend_Translate::getCache(); $this->assertTrue($cache instanceof Zend_Cache_Core); $this->assertTrue(Zend_Translate::hasCache()); $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1 (en)'), 'en'); $adapter = $lang->getAdapter(); $this->assertTrue($adapter instanceof Zend_Translate_Adapter_Array); $adaptercache = $adapter->getCache(); $this->assertTrue($adaptercache instanceof Zend_Cache_Core); Zend_Translate::clearCache(); $this->assertTrue(Zend_Translate::hasCache()); Zend_Translate::removeCache(); $this->assertFalse(Zend_Translate::hasCache()); }
/** * @group ZF-10034 */ public function testSetCacheFromCacheManager() { $configCache = array('translate' => array('frontend' => array('name' => 'Core', 'options' => array('lifetime' => 120, 'automatic_serialization' => true)), 'backend' => array('name' => 'Black Hole'))); $this->bootstrap->registerPluginResource('cachemanager', $configCache); $options = $this->_translationOptions; $options['cache'] = 'translate'; $resource = new Zend_Application_Resource_Translate($options); $resource->setBootstrap($this->bootstrap); $resource->init(); $this->assertTrue(Zend_Translate::getCache() instanceof Zend_Cache_Core); Zend_Translate::removeCache(); }