Zend Cache在一段时间后没有检索缓存项

时间:2010-05-13 04:44:29

标签: zend-framework caching

我正在使用Zend Cache进行页面缓存,但似乎在一段时间后错过了缓存。有一段时间没关系,但我明天回来并点击页面,它不会从缓存中获取内容。为什么呢?

$frontendOptions = array(
    'content_type_memorization' => true, // This remembers the headers, needed for images
   'lifetime' => NULL,                   // cache lifetime forever
   'automatic_serialization' => true,
   'automatic_cleaning_factor' => 0
);

$myPageCache = new Zend_Cache_Frontend_Page(array(
    'debug_header' => false,
    'automatic_cleaning_factor'=>0,
    '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
    )));


$backendOptions = array('cache_dir' => '.' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR);

$cache = Zend_Cache::factory($myPageCache,
                             'File',
                             $frontendOptions,
                             $backendOptions);

$cacheKey = hash('md5', "cache_" . $cachePath); // cachePath is the key I use for the cache

if(!$cache->start($cacheKey)) {
I output html here
 $cache->end();
}

2 个答案:

答案 0 :(得分:3)

事实上。我读了静态方法

Zend_Cache::factory($frontend, $back, $frontendOptions, $backendOptions, ...) 

只有在传递$frontendOptions参数的字符串时才使用$frontend。当您正在执行具体实例时,将忽略$frontendOptions

如果您仍想将具体实例$myPageCache传递到工厂,那么您似乎需要将lifetime参数(和其他参数)传递给创建实例的调用。否则,您可以加载单个$frontendOptions数组并使用:

$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);

答案 1 :(得分:0)

啊...... opps。

是因为我的'生命'=> NULL,被忽略了吗?

相关问题