Nov
19

Today's caching example builds on yesterday's with one key difference, the last line. But before I explain that line, this is the perfect opportunity to talk about two different types of caches in ColdFusion 9: template cache and object cache. The word "template" is relatively specific to ColdFusion. I haven't heard any other programming language refer to code files as templates. Following this nomenclature, the template cache in ColdFusion 9 refers to a specific area of cache where page fragments and full page cache items are stored. The second cache is referred to as the object cache. Virtually anything can be stored in object cache such as strings, arrays, ColdFusion components, queries, XML, or the like. In later posts I'll dive much deeper in to the object cache as it's the most flexible way to utilize Ehcache in ColdFusion 9.

Here's todays code:

<cfcache action="cache" timespan="#CreateTimeSpan(0,0,0,10)#">
    <cfoutput>This date/time IS cached: #Now()#<br /></cfoutput>
</cfcache>

<cfoutput>This date/time is not cached: #Now()#</cfoutput>

<!--- Get the little bit of template cache metadata you can. --->
<cfdump var="#GetAllTemplateCacheIDs()#">

Results in a browser:

The last line in this example shows the use of an undocumented function in ColdFusion 9, GetAllTemplateCacheIDs(). This function returns the ID of every item stored in the template cache. If at the time you called this function the server had three page fragment cache items and two full page cache items, five results would be displayed in the <cfdump>. Looking at the results you can see ColdFusion creates the cache ID by using the template URL and a unique identifier, followed by the line number the <cfcache> tag was on.

Knowing this information isn't very useful as you can't use it to do anything with the template cache. You can cache a page or a page fragment, and you can flush a page or a page fragment from the cache. But that's it. In later posts I'll show how much more metadata is available for the object cache.

Before I end this post I'd like for you to look back at the metadata dump. Can you draw any conclusions from the fact ColdFusion uses the URL of the template as part of the cache ID? If not, come back tomorrow where I'll show how this is important when flushing pages from the template cache.

Click here to download the code mentioned in this post.

Aaron West's Gravatar
About this post:

This entry was posted by Aaron West on November 19, 2009 at 8:00 AM. It was filed in the following categories: ColdFusion. It has been viewed 7143 times and has 0 comments.

13 related blog entries

0 Responses to 14 Days of ColdFusion 9 Caching: Day 3 - Viewing Page Cache Metadata