/** * 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)); }
/** * Prepend temp path to paths * * @param Zend_Config $config */ protected function _prependPath(Zend_Config $config) { $app = $this->getApp(); // File $fileOptions = Zym_Cache::getBackendOptions('file'); if (isset($fileOptions['cache_dir'])) { $fileOptions['cache_dir'] = $app->getPath(Zym_App::PATH_DATA, $fileOptions['cache_dir']); } Zym_Cache::setBackendOptions('file', $fileOptions); // Sqlite $sqliteOptions = Zym_Cache::getBackendOptions('sqlite'); if (isset($sqliteOptions['cache_db_complete_path'])) { $sqliteOptions['cache_db_complete_path'] = $app->getPath(Zym_App::PATH_TEMP, $sqliteOptions['cache_db_complete_path']); } Zym_Cache::setBackendOptions('sqlite', $sqliteOptions); }
/** * 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'); } }