2015-06-23 17 views
1

Я работаю над оптимизацией приложения Zend Framework с Doctrine ORM. Я не могу понять, какой именно код я бы использовал в своем контроллере, чтобы получить это кеширование. Всякий раз, когда я передаю снова тот же url, он должен использовать код кэша вместо обработки этой логики.Zend Framework 1 - Кэширование Zend

Мой Bootstrap файл для кэша выглядит следующим образом: -

protected function _initCache() { 

$frontendOptions = array(      
    'lifetime' => 7200, 'content_type_memorization' => true, 
    'default_options' => array( 
     'cache'      => true, 
     'cache_with_get_variables'  => true, 
     'cache_with_post_variables' => true, 
     'cache_with_session_variables' => true, 
     'cache_with_cookie_variables' => true,), 
     'regexps' => array( 
      // cache the whole IndexController 
      '^/.*'  => array('cache' => true), 
      '^/index/' => array('cache' => true), 
      // place more controller links here to cache them 
     ) 
    ); 

$backendOptions = array(
    'cache_dir' => APPLICATION_PATH ."/../cache" // Directory where to put the cache files 
); 

$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions); 
$cache->start(); 
Zend_Registry::set("cache", $cache); 
} 

Любая помощь будет оценена.

ответ

0

Проверьте этот ниже код, чтобы установить кеш, если он не существует, или получить кеш, если он существует.

$result =””; 
$cache = Zend_Registry::get('cache'); 

if(!$result = $cache->load('mydata')) { 
    echo 'caching the data…..'; 
    $data=array(1,2,3); // demo data which you want to store in cache 
    $cache->save($data, 'mydata'); 
} else { 
    echo 'retrieving cache data…….'; 
    Zend_Debug::dump($result); 
}