kolber / stacey

Cheap & easy content management
http://staceyapp.com
MIT License
1.04k stars 131 forks source link

Write site-state MD5 to a [cacheid].state file and check against this instead of comments #38

Closed alibosworth closed 12 years ago

alibosworth commented 12 years ago

This avoids an issue where cached JSON was never being retrieved because JSON can't have comments.

Original issue described in more detail here: https://github.com/kolber/stacey/issues/37

kolber commented 12 years ago

This is a really good idea. Using the comment tags has clearly become quite a brittle way to handle caching.

As opposed to maintaining a separate state file, what do you think of the idea of naming the cache file as a combination of the the hash of the url requested combined with the hash of the contents. So something like asd1234-dsa4321. Where asd1234 is a hash of the URL requested and dsa4321 is a hash of the contents of the file.

Then we can prevent a potentially infinite number of cache files by checking against the first half of the filename and deleting it once expired, then use the second half to check whether the cache needs to be invalidated or not.

alibosworth commented 12 years ago

Yeah, I thought about doing that, and I actually started trying to do it but decided against it when I realized that garbage collection was going to be more complicated.

I'm all for it though if you can think of a clean way to do it. Is there going to much of a performance hit to having to scan through file names for cleanup? I agree it is slightly messy to have two files, but it is also nice that the two files are instantly addressable rather than having to loop through checking against parts of every file name - that being said perhaps there is a great way to handle that which I'm not aware of.

I guess it would be worth seeing how this problem has been solved before, as it certainly isn't a unique one.

I've really been enjoying Stacey over the past few days, just about to relaunch my site with it (switching from indexhibit), thanks!

Ali

kolber commented 12 years ago

I figure that using the file name will definitely be faster than the current method, which involves reading contents of the cache file and running regexes against it. Definitely not as quick as maintaining a single .state file, but I'll pull in your changes, run some tests and compare them.