【问题标题】:Zend Cache doesn't read from its cacheZend Cache 不从它的缓存中读取
【发布时间】:2013-12-18 22:15:29
【问题描述】:

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

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

我错过了什么吗?

即使我从配置中删除 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();
}

【问题讨论】:

    标签: php zend-framework caching zend-cache


    【解决方案1】:

    来自 zend 文档:

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

    read more

    【讨论】:

    • 我觉得这里没问题。 Zend_Cache 为 start() 自动生成 id,为什么 Zend_Cache 为相同的内容生成另一个 id(和缓存文件)?
    • 如果不指定 start() 方法的参数,zend 从 'Get'、'Post'、'Session'、'Files' 和 'Cookie' 创建 id。你确定每次都是一样的吗?
    猜你喜欢
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 2012-09-10
    相关资源
    最近更新 更多