Smart caching

As you may know, CFML offers the possibility to cache a query whithin a certain timespan. While working on the tag <cfcache> we thought about improving the tag by a certain option we would like to have your opinion about.

The tag <cfcache> allows programmers to store a complete page in a certain caching directory and reload it from this directory when the timestamp of the page has exceeded the time defined in the timespan attribute. This works for all kind of GET variables. For POST variables the result is unusable. Railo has implemented the tag to work exactly in the same manner as it does in CFMX. But...
By adding a certain functionality to the tag <cfcache> it would largely gain importance for programmers. We thought about adding a closing tag to the <cfcache> tag and cache everything between the opening and closing tag until the timeout has occured. Let us take the following example:


<cfcache action="CONTENT" timespan="#createTimeSpan(...)#" key="#xfa.action#">
<cfquery name="getHeader" datasource="db">
Select headerImage from headers where headerID = #url.headerID#
</cfquery>
...
some code
...
<cfoutput><img src="#getHeader.headerImage#"></cfoutput>
</cfcache>
The attribute key is necessary to add a certain individuality for programmers. So you can add your own custom keys in order to specify the cache in more details. Within the next 60 seconds the content of the tag will be read its data from cache and display it if:
  • cgi.script_name and cgi.query_params are the same
  • the attribute key contains the same value
Since you can use any ressource for storing the cache files even caching in RAM is an option by using the ram ressource. If you have any notes on this functionality, just let us know...

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.002. Contact Blog Owner