ColdFusion 9 caching example

Sometimes with the new/updated features you don't get a chance to implement them right away. Well today I was working on a pulling in feed when I figured I finally had a good use-case to check out the updated caching enhancements in ColdFusion 9.

For this site I was working on I needed to pull in an RSS feed but HTTP calls are slow as there are usually factors outside of your control. The ColdFusion caching functions allows some nice control over what is cached, how often the cached is refreshed, and even when to drop it completley via the following two parameters:

  1. time span ( when we need to re-cache the item )
  2. idle/drop time ( When to drop it from memory when it hasn't been accessed for X amount of time )

Posted: 19-Aug-2010

View: 3423

Permalink: here

Comments

It's nice to see some more folks blogging about CF9 caching. I have a similar speed problem with cfsharepoint so I'm looking into caching solutions as well. Right now I'm deciding between native CF9 caching and Luis Majano's standalone CacheBox.

I'd advise against the use of arrayContains(cacheGetAllIds(),"MYTWITTERFEED") in your example. The biggest problem is that it assumes that if "myTwitterFeed" is in cacheGetAllIds(), then the cacheGet("myTwitterFeed") that follows will get a cache it. However, it is possible for "myTwitterFeed" to be expired from the cache between the two calls, leaving with feedQry being set to Null.

The recommended approach is to set feedQry = cacheGet("myTwitterFeed") first, then use isNull(feedQry) in your if condition. I suspect cacheGet() is a little faster than cacheGetAllIds() so you may even get a performance improvement from the change.

#1 Dennis Clark
22/Aug/10 7:56 PM