Query caching in Railo and CFMX
Caching queries is something that one should use since it can dramatically speed up the delivery of a page.
Anyhow, there are and were some differences between Railo and CFMX. One was, that in Railo if you wanted to flush the querycache, you only had the way of using the tag: <cfobjectcache action="clear">. This would then purge all the queries from the query cache. But what if you wanted to flush only one single query from the cache?
CFMX (and now Railo) offers the way of caching a query like follows:
<cfquery name="getInformation" datasource="railo" cachedwithin="#CreateTimeSpan(0,0,0,0)#">
Select * from test_first
</cfquery>
<cfquery name="getInformation" datasource="railo" cachedwithin="#CreateTimeSpan(0,0,0,0)#">
Select * from test_first
</cfquery>
<cfdump var="#getInformation#">
<cfquery name="updateInformation" datasource="railo">
Update test_first set name = 'b+c+d#GetTickCount()#' where p_id = 2
</cfquery>
<!--- if I would select and dump the query again, no change would be reflected, so according to the Adobe Documentation the following query should flush the query from the cache --->
<cfquery name="getInformation" datasource="railo" cachedwithin="#CreateTimeSpan(0,0,0,0)#">
Select * from test_first
</cfquery>
<!--- Now this displayes the changed query: correct --->
<cfdump var="#getInformation#">
<!--- This is just to have a certain delay in the update --->
<cfset sleep(1000)>
<!--- Assuming the documentation is right, the query should not be in the cache anymore, so I am updating it --->
<cfquery name="updateInformation" datasource="railo">
Update test_first set name = 'susi#GetTickCount()#' where p_id = 2
</cfquery>
<cfquery name="getInformation" datasource="railo" cachedwithin="#CreateTimeSpan(0,0,1,0)#">
Select * from test_first
</cfquery>
<!--- Very interesting is, that this code does not reflect the last change I made, instead I get the query that has been stored into the cache a couple of lines above when I used the cachedwithin="#CreateTimeSpan(0,0,0,0)#" setting --->
<cfdump var="#getInformation#">
In addition every query CFMX gets from the cache is copied to the variable you use for it. In Railo you will only get a pointer pointing to the cached query. It will only be copied as soon as it is changed with QuerySetCell() or similar functions. This of course is much faster in 90% of the cases than copying it every time. This is why Queries in CFMX even though cached can consume some time. In Railo they are almost always executed with 0ms. You can read an earlier post about querycaching.
In Railo 2.1 we will enhance the functionality of the <cfobjectcache> tag. Sometimes, when you update a table and want all queries relying on this table to be flushed from the cache. So we will add the attribute filter to the tag. You can pass a regular expression to it like follows:
<cfobjectcache action="clear" filter="test_([0-9]+)"



There are no comments for this entry.
[Add Comment]