/** * Make sure set config works * */ public function testSetConfigShouldWork() { $config = new Zend_Config(array( 'default_backend' => 'File', 'frontend' => array( 'Core' => array('caching' => false) ), 'backend' => array( 'APC' => array(), 'File' => array('cache_dir' => '/tmp'), 'Sqlite' => array( 'cache_db_complete_path' => 'foo/bar.sqlite' ) ) )); Zym_Cache::setConfig($config); $this->assertEquals(Zym_Cache::getDefaultBackend(), 'File'); $this->assertEquals(Zym_Cache::getBackendOptions('Apc'), array()); $this->assertEquals(Zym_Cache::getBackendOptions('sqlite'), array( 'cache_db_complete_path' => 'foo/bar.sqlite' )); $this->assertEquals(Zym_Cache::getFrontendOptions('Core'), array('caching' => false)); }
/** * Setup cache after resources are setup * * @internal * @param Zym_Message $message */ public function onAfterResourceSetup(Zym_Message $message) { $sender = $message->getSender(); if ($sender instanceof Zym_App_Resource_Cache) { $config = $this->getConfig('cache'); $backend = $config->get('backend') ? $config->get('backend') : Zym_Cache::getDefaultBackend(); $backendConfig = Zym_Cache::getBackendOptions($backend); $frontendConfig = Zym_Cache::getFrontendOptions('Core'); // Save $filename = $this->getPath(self::PATH_DATA, 'cache'); $cache = Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true, 'cache_id_prefix' => $this->getName(true) . '__' . $this->getEnvironment() . '__' . get_class($this) . '__'), array('cache_dir' => $filename, 'file_name_prefix' => get_class($this))); $cache->save(array($backend, $frontendConfig, $backendConfig), 'cache'); } }