Php 科哈纳,编辑缓存不';你看不见吗?

Php 科哈纳,编辑缓存不';你看不见吗?,php,optimization,caching,kohana,Php,Optimization,Caching,Kohana,我正在为我的站点设置缓存,但是很难测试缓存是否正常工作。我的控制器中有以下内容: public function read($id, $slug = null) { $this->cache = Cache::instance(); $story = $this->cache->get("story".$id); if (!$story) { $story_model = new Story_Model; $story = $story_model

我正在为我的站点设置缓存,但是很难测试缓存是否正常工作。我的控制器中有以下内容:

public function read($id, $slug = null)
{
  $this->cache = Cache::instance();
  $story = $this->cache->get("story".$id);

  if (!$story) {
    $story_model = new Story_Model;
    $story = $story_model->get_story($id);
    if (!$story) throw new Kohana_404_Exception();
    $this->cache->set("story".$id, $story);
  }

  $this->template->content = new View('story');
  $this->template->title = htmlspecialchars($story->title);
  $this->template->content->story = $story;
}
这很好,我甚至可以验证是否找到了缓存,并且在设置缓存后没有输入if()检查。我的困惑是,为什么当我编辑缓存文件时,更改没有反映在视图中?例如,我的缓存如下所示:

O:8:"stdClass":11:{
  s:2:"id";s:3:"636";
  s:5:"title";s:45:"Some Article Title";
  s:4:"link";s:50:"http://www.somesite.com";
  s:8:"category";s:2:"12";
  s:4:"user";s:1:"5";
  s:4:"slug";s:45:"some-article-title";
  s:7:"pubdate";s:19:"2009-08-05 03:57:50";
  s:6:"sticky";s:1:"0";
  s:7:"summary";N;
  s:13:"categorytitle";s:13:"International";
  s:8:"username";s:7:"usernameHere";
}
如果我将
title
值更改为“Some Article title Part 2”,并刷新我的视图,我仍然会看到旧的标题名称,并且对缓存文件所做的更改也会消失

我做错了吗?如何测试是否正在访问缓存文件而不是数据库?我的配置文件内容如下:

$config['default'] = array
(
  'driver'   => 'file',
  'params'   => APPPATH.'cache',
  'lifetime' => 1800,
  'requests' => 1000
);

序列化的PHP对象对值进行约束。请看下面一行:

s:5:"title";s:45:"Some Article Title";
s:5
表示以下值将包含五个字符
“T-i-T-l-e”
。总共五个。下一个值
s:45
应该有45个字符。您将文本从原来的内容更改为
“某些文章标题”
,以便在此处发布,但原始内容总共包含45个字符

添加更多字符或减去字符将打破值的字符串长度与与与之关联的int-val之间的关系。如果
s:3
,则字符串长度应为三个字符


只需更改两个字符,而不是在值上加/减。将
“Title”
更改为
“Ninja”
,然后刷新页面。

您需要编辑原始数据存储中的数据,并将缓存视为一个黑匣子

如果使用数据库,请使用一个好的数据库管理器,以便轻松编辑值。我用。。。别问我为什么

使用文件缓存驱动程序时,我将删除application/cache下的所有内容,以便清除缓存并测试缓存代码


我编辑缓存文件的唯一时间是,如果我真的在编写缓存系统来替换文件或memcached驱动程序。

在JSON中不会有问题。在PHP中也不会有问题,只要您了解发生了什么。请注意,我想Kohana建议使用
html::specialchars()
而不是原生PHP
htmlspecialchars()
(尽管我不记得为什么)