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
SELECT first_name,last_name,email,zip FROM member LIMIT 30
You should see something like this:
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.
Displaying #start# to #endc# of #records.recordcount# records
< Prev
#NumberFormat(pc,’00’)#
#NumberFormat(pc,’00’)#
Next >