ScopeCache on RIAForge

This post is more than 2 years old.

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.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by John C. Bland II posted on 2/28/2008 at 9:28 PM

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.

Comment 2 by Raymond Camden posted on 2/28/2008 at 9:31 PM

John, I read your question twice - and I still don't get it. What are you asking?

Comment 3 by Aaron Lynch posted on 2/29/2008 at 3:16 AM

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.

Comment 4 by Raymond Camden posted on 2/29/2008 at 4:28 AM

Well, if so, the answer is no. ;) You can't dictate _where_ in the scope stuff is cached.

Comment 5 by Charlie Arehart posted on 3/1/2008 at 1:21 PM

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...

Comment 6 by Nate posted on 5/23/2008 at 2:56 AM

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.

Comment 7 by Raymond Camden posted on 5/23/2008 at 4:55 AM

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.

Comment 8 by Nate posted on 6/2/2008 at 8:42 PM

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.

Comment 9 by Raymond Camden posted on 6/2/2008 at 10:51 PM

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.

Comment 10 by Nate posted on 6/4/2008 at 1:49 AM

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?

Comment 11 by Raymond Camden posted on 6/4/2008 at 5:39 PM

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.

Comment 12 by Nate posted on 8/8/2008 at 9:50 PM

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.

Comment 13 by Raymond Camden posted on 8/9/2008 at 12:00 AM

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.)