Today a discussion about partial page caching came up on cf-talk. I mentioned a custom tag I had written about for CFDJ, ScopeCache. I could have sworn I blogged about it before, but since I couldn't find it in my archives, I must have forgotten.
So, with that in mind, I decided to add a few new features to it and upload it. ScopeCache allows you to easily cache partial page content. This is done by simply wrapping content:
do some slow stuff here
This code will cache the result of the code inside the call for thirty minutes. The older version didn't even have a timeout. (Don't ask me why, I just never added it.) You can set a timeout to a specific date and time, or by a number of seconds.
Also included are dependancies. This allows you to "chain" caches. So if cache item A has a dependancy of B, it means that when A is cleared, or removed because of a timeout, then B will be cleared as well. This process is chained so that if B had dependancies, they will be cleared as well.
The next feature I'm considering adding is a "size" to the cache. This would allow you to say "Only cache N items". Removal would be done like .Net's cache system - each item in the cache would have a "weight" and the lightest items would be removed first. (By the way, if you haven't checked it out, the built-in cache system in .Net is very sweet.)
If you have any questions, or suggestions, about this code, just let me know.
Edited Oops, a link would help, wouldn't it? You can download the code here.