Smart caching

March 28, 2007 · By Gert Franz · 4 Comments

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#
some code
<cfoutput><img src="#getHeader.headerImage#"></cfoutput>
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...

Tags: Features

4 responses so far ↓

  • 1 Alan Williamson // Mar 29, 2007 at 11:02 AM

    In BlueDragon, we have a tag &lt;cfcachecontent&gt; that does exactly this, and a lot more, allowing you to persist to directory or database.

    We also allow you to group your caches, allowing you to quickly flush groups or individual cached items.

    We didn't override the &lt;cfcache&gt; as this causes confusion with the current implementation. Two completely different caching techniques.
  • 2 Streit // Mar 29, 2007 at 12:08 PM

    there is a little missunderstanding in the description of the tag cfcache, it will looks like this:
    &lt;cfcache action=&quot;content&quot; timespan=&quot;#...#&quot; key=&quot;#xfa.action#&quot;&gt;
    &lt;cfquery name=&quot;getHeader&quot; datasource=&quot;db&quot;&gt;
    Select headerImage from headers where headerID = #url.headerID#
    some code
    &lt;cfoutput&gt;&lt;img src=&quot;#getHeader.headerImage#&quot;&gt;&lt;/cfoutput&gt;

    first if you want to use as cache only for a part of the page, you have to set the attribute &quot;action&quot; to &quot;content&quot;, the you still use the attribute &quot;timespan&quot; to define the timepan for the cache, then at last the attribute &quot;key&quot; is optional.
  • 3 Streit // Mar 29, 2007 at 12:46 PM

    hi alain

    i does not know this tag (cfcachecontent) and i have also not found any docu for it.
    you write &quot;We didn't override the &lt;cfcache&gt; as this causes confusion with the current implementation. Two completely different caching techniques.&quot;

    But both are caching mechanisms, when i follow your meaning, you should also have a tag like &quot;cffileUpload&quot; or &quot;cffileWrite&quot; insteat of &quot;cffile&quot;, because this are 2 completly different file manipulation techniques. for that we have the attribute &quot;action&quot; to control this. in the case of the tag &quot;cfcache&quot; you have to use the action &quot;content&quot; (alias &quot;contentcache&quot;).

    you still can use the tag &quot;cfcache&quot; the same way as in Neo, but if you use it with attribute action=&quot;content&quot;, you dont have to learn a completly new tag, because you can use most attributes in the same way.

    then you write &quot;allowing you to persist to directory or database&quot;, one of the biggest feature of railo 1.1 are the resources, you can not only invoke the local filesystem with tags like [cffile, cfdirectory, cache ...] or in functions like [fileExists ...], you always have the possibility to use all resources defined for your enviroment (you can also extends your own).

    &lt;cfcache ... directory=&quot;ram://this/store/in/Memeory&quot;&gt;
    &lt;cfcache ... directory=&quot;d:/this/store/local&quot;&gt;
    (or &lt;cfcache ... directory=&quot;file://d:/this/store/local&quot;&gt;)
    &lt;cfcache ... directory=&quot;zip://d:/my/zip/!/cache&quot;&gt;
    &lt;cfcache ... directory=&quot;;&gt;
    &lt;cfcache ... directory=&quot;datasource://mydatasource/to/db/&quot;&gt;

    in railo 1.1 you not only can use database or directory as a cache pool, you can also use a many more.
  • 4 Fred B // Sep 19, 2007 at 1:15 PM

    You should add this to the list of enhanced tags.

Leave a Comment

Leave this field empty: