簡體   English   中英

Zend框架1-Zend緩存

[英]Zend Framework 1 - Zend Caching

我正在使用Doctrine ORM優化Zend Framework應用程序。 我無法弄清楚我將在控制器中使用哪些特定代碼來獲得此緩存。 每當我再次傳遞相同的URL時,都應使用緩存代碼,而不是再次處理該邏輯。

我用於緩存的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);
} 

任何幫助,將不勝感激。

檢查以下代碼以設置緩存(如果不存在)或獲取緩存(如果存在)。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM