advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Partners & Affiliates
advertisement
advertisement
Rate this item | 0 users have rated this item.
 Print Print
 
Build a Better ColdFusion Cache Tag
ColdFusion's <cfcache> tag is great, but it caches only whole HTML pages and most templating systems won't play along. Learn how to develop a custom tag that allows you to cache arbitrary sections of ColdFusion-generated pages. 

advertisement
aching is an essential strategy for improving the performance of your applications, and ColdFusion offers much pre-packaged functionality to assist in this area, including a number of application server caching settings in the ColdFusion Administrator. ColdFusion also offers caching options directly through ColdFusion tags. For example, developers can use the <cfquery> tag's cachedAfter and cachedWithin settings to cache the results of database queries and the <cfcache> tag for its direct support of user-interface caching.


The <cfcache> tag is not without its limitations, however. It works very well when you want to cache a whole HTML page, but if you want to cache just part of a page, you are out of luck. The "page" is the smallest unit that <cfcache> can process. Such a restriction might be reasonable for simple applications, but almost any sophisticated application design uses some kind of templating system to assemble complex interfaces from a variety of individual ColdFusion scripts. As such, most modern application designs don't allow whole pages to be cached since to do so requires a single script to serve as the root point for the whole application.

Many ColdFusion frameworks, like the popular Fusebox or the newer Mach-II, require that all traffic go through the same ColdFusion script (usually named something like index.cfm). If you place a <cfcache> tag on this page, only the first page accessed ever gets displayed.

Luckily, it's quite easy to write a cache tag that can work with sections of pages, and this article describes a script that does just that. The tag is named CacheOMatic (click here to download it), so the first step is to create a file called CacheOMatic.cfm and save it to a directory where ColdFusion custom tags are stored (the paths indicated under the setting "Custom Tag Paths" in the ColdFusion Administrator, generally a default path that looks something like C:\CFusionMX\CustomTags).

When you want to cache a section of a page, you surround it with the tag <cf_CacheOMatic>, as in:


<cf_CacheOMatic>
Here's some stuff to cache!
</cf_CacheOMatic>

While you want to support a plain vanilla version of the tag, you also will add some optional parameters. The CacheOMatic tag will take the three inputs shown in Table 1, all optional.

Name The "Key" of the Cache
scope The scope in which you want to store this data; corresponds with ColdFusion scopes: application, session, and server
exp How long until the cache expires
Table 1. Optional Inputs for CacheOMatic

Page 1 of 2


advertisement
  Next Page: Verify Values
Page 1: IntroductionPage 2: Verify Values
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES