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
</cf_scopecache>
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.
Comment 1 written by Mike Brunt on 8 January 2004, at 1:06 PM
Comment 2 written by Tony on 8 January 2004, at 3:06 PM
Comment 3 written by Raymond Camden on 8 January 2004, at 3:10 PM
Comment 4 written by Tony on 9 January 2004, at 9:23 AM
Comment 5 written by Fiona on 25 March 2004, at 10:11 AM
Comment 6 written by Raymond Camden on 29 March 2004, at 7:53 AM
You can cache to the session, however, if you site has a large # of users and large # of dynamic pages, you could quickly generate a HEAVY load in RAM. In that case, I wouldn't use scope cache, or only cache some items.
Note your average RAM usage BEFORE using ScopeCache. Then note it afterwards. If you see an impact, a bad impact, scale back your use of scopecache.
Hope this helps a tiny bit.
Comment 7 written by hungry on 21 March 2007, at 3:41 PM
Comment 8 written by Raymond Camden on 21 March 2007, at 7:35 PM
[Add Comment] [Subscribe to Comments]