【问题标题】:CakePHP 1.3 cleares all cached pages after adding new postCakePHP 1.3 添加新帖子后清除所有缓存页面
【发布时间】:2014-04-04 18:49:39
【问题描述】:

我正在使用 CakePHP 1.3 并尝试为视图页面启用缓存,缓存系统工作正常并缓存所有页面。但是当我们添加新帖子(向数据库插入新记录)或编辑旧帖子(更新表的记录)时,CakePHP 会删除所有缓存的页面,而不仅仅是已编辑的页面!

app/config/core.php:

Cache::config('default', array('engine' => 'File','duration' => 8640000));

app/controllers/articles_controller.php:

var $helpers = array('Cache');
var $cacheAction = array(
    'view' => array('duration' => 8640000), 
    'latest' => array('duration' => 8640000), 
);

我如何告诉 Cake 只删除更改页面的缓存版本而不是所有缓存页面?

【问题讨论】:

  • 感谢桑普森先生的编辑。你知道我该如何解决这个问题吗?

标签: cakephp caching cakephp-1.3


【解决方案1】:

这实际上很难,所以我不能只给你一段代码来解决这个问题。您需要编辑管理缓存的 lib 文件夹中的实际蛋糕文件。注意:这是蛋糕人超级不推荐的。但是lib/Cake/Cache/Engine/FileEngine.php 是具有文件引擎操作的文件。您似乎对删除功能感兴趣:

/**
 * Delete a key from the cache
 *
 * @param string $key Identifier for the data
 * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
 */
public function delete($key) {
    if ($this->_setKey($key) === false || !$this->_init) {
        return false;
    }
    $path = $this->_File->getRealPath();
    $this->_File = null;

    //@codingStandardsIgnoreStart
    return @unlink($path);
    //@codingStandardsIgnoreEnd
}

此外,您可以添加自己的文件引擎并通过移动代码并在那里扩展代码来使用蛋糕引擎的一部分,而不是编辑核心蛋糕文件(这在开源中非常酷)。

通过阅读用于实现文件缓存引擎的代码,您也有可能找到您的实际解决方案。祝你好运。

【讨论】:

    猜你喜欢
    • 2016-05-04
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2017-05-24
    • 1970-01-01
    相关资源
    最近更新 更多