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:
<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.
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 1414 times and has 0 comments.
13 related blog entries
- 14 Days of ColdFusion 9 Caching: Day 14 - Setting the Server Cache Properties (November 30, 2009)
- 14 Days of ColdFusion 9 Caching: Day 13 - Retrieving the Server Cache Properties (November 29, 2009)
- 14 Days of ColdFusion 9 Caching: Day 12 - Removing All Items in Cache (November 28, 2009)
- 14 Days of ColdFusion 9 Caching: Day 11 - Reporting On All Items in Cache (November 27, 2009)
- 14 Days of ColdFusion 9 Caching: Day 10 - Session-Specific Caching (November 26, 2009)
- 14 Days of ColdFusion 9 Caching: Day 9 - Dependent Caching (November 25, 2009)
- 14 Days of ColdFusion 9 Caching: Day 8 - Cache Hits and Cache Misses (November 24, 2009)
- 14 Days of ColdFusion 9 Caching: Day 7 - Using cacheRemove to Flush Items from Cache (November 23, 2009)
- 14 Days of ColdFusion 9 Caching: Day 6 - Using cachePut, cacheGet, and cacheGetMetadata (November 22, 2009)
- 14 Days of ColdFusion 9 Caching: Day 5 - The Difference Between Timespan and Idletime (November 21, 2009)
- 14 Days of ColdFusion 9 Caching: Day 4 - Flushing a Template From Cache (November 20, 2009)
- 14 Days of ColdFusion 9 Caching: Day 2 - Caching a Page Fragment (November 18, 2009)
- 14 Days of ColdFusion 9 Caching: Day 1 - Caching a Full Page (November 17, 2009)



Tweet