Last night I released ScopeCache on RIAForge. This isn't new code. It's the caching custom tag I've had for a few years now. Charlie Arehart mentioned to me that it wasn't possible to find the code anymore (outside of BlogCFC), so now I have a place for folks to find it.
I also did some small updates to it, including giving it the ability to cache in the request scope.
For folks who don't know what this tag is, it's a basic way to quickly add caching to a page. So imagine the following slow code:
<cfset sleep(9000)>
Done sleeping.
I can cache the result of this code (the output) by adding the custom tag:
<cf_scopecache scope="application" name="mycodeisntslow" timeout="3600">
<cfset sleep(9000)>
Done sleeping.
</cf_scopecache>
Pretty simple, right? There are more options of course. See the documentation in the tag itself.
Archived Comments
Can I put the cache in the application scope but in my cache struct inside of that scope?
ie - application.cache.mycodeisntslow vs application.mycodeisntslow
Thanks.
John, I read your question twice - and I still don't get it. What are you asking?
I think he is asking if he can store the cached data in a struct of his own choosing.
In other words, instead of just scope="Application", there could be an optional attribute of structName...
scope="Application" structName="cache"
That is my take on it at least.
Well, if so, the answer is no. ;) You can't dictate _where_ in the scope stuff is cached.
Thanks for posting it, Ray. I've now updated my pointer to it (along with many other CF-based caching solutions--and several dozen other CF tools) at:
http://www.carehart.org/res...
I just learned about this custom tag today and it's really helped me out in a big way. Many thanks for this great work of yours. I've got a question. When would you want to use this with the request scope. I can understand how this is used in the application of server scope, but I can't imagine how it's useful in the request scope.
I honestly can't think of a great reason to use the Request scope for the cache, but since it was so easy to add support, I figured what the hey.
Can you think of a reason why some code fragments inside a cf_scopecache tag might randomly get repeated when first cached? Clearing the cache seems to correct this problem most of the time.
Yes, I can think of a way. Maybe the tag gets confused and both caches and lets the original output through.
I don't see this here, but if you can try to make a reproducible case, I'd definitely appreciate it.
It turns out that my problem had absolutely nothing to do with Scopecache. It was a problem in a SQL query and I was simply confused because I made that change at the same time that I added your Scopecache.
I have a new question for you / feature request.
Let's say Scopecache caches 10000 code fragments and the memory/size of those variables starts taking up too much RAM. Might it be a nice feature to automically clear 2000 or so variables(those variables with the smallest hit count) when that happens?
Yeah, that would be nice. I'd like to have a optimize type action that takes a 'strength' (ie, how much to clean) and the tag will clear out based on hitcount/last used type values.
Here's another feature request if you ever find the time for it...
How about a way to save the cache and restore it at a later time after a server is shutdown and restarted? Keeping a history of the cache on a daily or weekly basis would be a very nice feature.
Ah, so basically, cache to the file system. In theory, you could do expires="never" then.
Log a bug request for this at RIAForge. (If I didn't turn it on, bribe me with a beer and I'll do so.)