简体   繁体   中英

Zend Framework 1 - Zend Caching

I am working on optimizing Zend Framework Application with Doctrine ORM. I can't figure it out what particular code would I use in my controller to get this caching. Whenever I pass again the same url it should use the cache code instead of processing that logic again.

My Bootstrap file for cache looks like this:-

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);
} 

Any help would be appreciated.

Check this below code to set cache if not exist or get cache if exists.

$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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM