ColdFusion 10 Query Caching with Ehcache – Part 2

A quick follow up to the part 1 of caching queries in Ehcache with ColdFusion.

In ColdFusion 9, we were forced to work the long way of figuring out if a query object was in the cache and if it wasn’t then to use cachePut() and insert it. With ColdFusion 10, we’ve got some improved caching features that makes the default cache be the Ehcache layer.

Instead of writing:





	
    
        SELECT first_name,last_name,email,zip
        FROM member
        LIMIT 30
    
    
	



All we’re going to need to write is the query, with one new attribute: cacheId.



	SELECT first_name,last_name,email,zip
	FROM member
	LIMIT 30



When you’re testing this new feature out, what you should do is confirm that the cacheId exists in the cache and that everything is working accordingly. We’re going to retrieve a list of cache objects in the Ehcache by calling cacheGetAllIds(). This function allows you to enter the name of the cacheRegion and you can also define your cacheRegion as another attribute on the tag. By default, the cacheRegion is set to "query", so all you’ll need to do is update the function to be cacheGetAllIds(“query”). When we take a look at the final code, we’re going to end up with what you see below. Again, you don’t have to define the cacheRegion attribute on the , but I’m just demonstrating.






	SELECT first_name,last_name,email,zip
	FROM member
	LIMIT 30



You should see something like this:

coldfusion 10 ehcache example

Again, there really isn’t much to demo, but I’ve provided the code and a large sample table for you to do some testing with on your own.

As a final note, if you do wish to not use Ehcache as your default cache layer and you wish to use the previous default caching layer, you can do so by checking a box in the ColdFusion administrator. I’ve added a screenshot below to help you find the option.

disabling coldfusion 10 ehcache as default cache

1 thought on “ColdFusion 10 Query Caching with Ehcache – Part 2”

Leave a Reply

Your email address will not be published. Required fields are marked *