Ask a Jedi: Using ehcache with stored procs in ColdFusion

This post is more than 2 years old.

Hal asked:

Do you know if it's possible to use ehcache with stored procs in CF?

The answer is yes - but it is important to be clear that when you use the built in query caching (both cfquery and cfstoredproc have automatic support for caching) you are not using the new ehcache-based caching in ColdFusion. Sure it still caches - but it isn't using ehcache under the covers like the newer caching features added to ColdFusion 9.

Can you use the new caching functions to store stored proc results? Of course! Don't forget that the new caching functions take any data, period. So you could easily do something like so (warning - pseudo-code):

<cfif isNull(cacheGet("mystoredproc"))> <cfstoredproc procedure="getBeer" result="result"> <cfset cachePut("mystoredproc", result)> <cfelse> <cfset result = cacheGet("mystoredproc")> </cfif>

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

Archived Comments

Comment 1 by Ryan posted on 12/6/2010 at 10:38 PM

What would be the benefit of putting this in ehcache as opposed to the query caching? Or is there none?

Comment 2 by Raymond Camden posted on 12/6/2010 at 10:40 PM

ehcache is a -very- powerful caching system and you can tweak it's performance settings (if you don't mind getting into XML). So if you know ehcache and want to make use of it, then this would be a better option. (afaik)

Comment 3 by Matthew Lesko posted on 12/7/2010 at 1:34 AM

To build on Ray's comment. Most interesting usage scenario I've done is disk persistence. And, if your database is only written through that application make the persistence permanent so that it stays around between CF restarts.