Ask a Jedi: Using ehcache with stored procs in ColdFusion

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 developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA