2

我正在使用 Doctrine ORM 优化 Zend 框架应用程序。我无法弄清楚我将在控制器中使用哪些特定代码来获取此缓存。每当我再次传递相同的 url 时,它应该使用缓存代码而不是再次处理该逻辑。

我的缓存引导文件如下所示:-

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

任何帮助,将不胜感激。

4

1 回答 1

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);
}
于 2015-11-20T09:09:08.270 回答