I'm working on setting up caching for my site, but am having difficulty testing whether the caching is working properly or not. I've got the following in my controller:
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;
}
This works just fine, I can even verify that the cache is being found, and the if() check is not being entered after the cache is set. My confusion is this, why is it when I edit my cache-file the changes aren't reflected in the view? For instance, my cache looks like this:
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";
}
If I changed the title
value to "Some Article Title Part 2," and refresh my view, I still see the old Title name, and the changes I made to the cache file vanish.
Am I doing it wrong? How can I test whether my cache files are being accessed instead of my database? My config file contents follow:
$config['default'] = array
(
'driver' => 'file',
'params' => APPPATH.'cache',
'lifetime' => 1800,
'requests' => 1000
);