kolber/stacey — Issue #37: JSON never retrieved from cache
Author: alibosworth
Created: 2012-02-19 08:53:51+00:00
State: open

I may be mistaken but is it possible that [this change](https://github.com/kolber/stacey/pull/7) may have caused caching to no longer work for JSON files?

Specifically the cache IS correctly written for JSON files but the lack of identifying comment containing the md5 within the cache file causes it never to be retrieved from the cache, causing all non-403d JSON requests to be re-rendered fully (which in my case is very slow because I am generating a list of all images across the site)

I suspect that this is the culprit (line 57 of cache.inc.php)

function get_current_hash() {
preg_match('/Stacey.*: (.+?)\s/', file_get_contents($this->cachefile), $matches);
return isset($matches[1]) ? $matches[1] : false;
}

If I remove 'json' from the $no_comment_types array, caching for JSON files resumes as normal, but of course the produced JSON is invalid because of the comments at the end.

I can't think of an easy fix considering the current caching mechanism appears to rely on the md5 being matched against within the comment at the end of each cached file.

Ideas?