1

我编写了一个函数来缓存我网站中的每个页面,并将这个函数放在 Bootstrap 文件中。

每个请求都会创建缓存文件,即使是同一个页面。

我错过了什么?

即使我从配置中删除 regexps 数组,它也不起作用。

Zend 1.12.3

protected function _initCache() {
    $cachePath = APPLICATION_PATH
        . DIRECTORY_SEPARATOR
        . '..'
        . DIRECTORY_SEPARATOR
        . '_cache';

    $fO = array(
        'lifetime' => 7200,
        'automatic_serialization' => true,
        'regexps' => array(
            '^/admin/' => array(
                'cache' => false
            ),
            '^/account/' => array(
                'cache' => false
            ),
            '^/cart/' => array(
                'cache' => false
            ),
        ),
        '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,
        ),
    );

    $bO = array(
        'cache_dir' => $cachePath
    );

    $cache = Zend_Cache::factory('Page', 'File', $fO, $bO);
    $cache->start();
}
4

1 回答 1

0

来自 zend 文档:

注意:使用 Zend_Cache 时,注意重要的缓存标识符(传递给 save() 和 start())。对于您缓存的每个资源,它必须是唯一的,否则不相关的缓存记录可能会相互擦除,或者更糟糕的是,会显示在另一个位置。

阅读更多

于 2013-12-18T22:34:20.630 回答