OpenBD Wiki

From OpenBD
Jump to: navigation, search

CFCACHECONTENT

Contents

Description

The CFCACHECONTENT tag allows you to cache specific blocks of HTML/CFML content to memory or a database table.

Syntax

<cfcachecontent action="action to perform" 
                cachename="cache name" 
                group="group name" 
                cachedwithin="timespan until cache expires">
  ... content to cache ...
</cfcachecontent>

Attributes

AttributeReq/OptDefaultDescription
actionrequiredcacheThe action to perform. Permitted values are:
  • CACHE (create the cache)
  • FLUSH (flush the cache with the name provided in the CACHENAME attribute)
  • FLUSHGROUP (flush the group with the name provided in the GROUP attribute)
  • FLUSHALL (flush all cached content)
  • STATS (return a variable named CFCACHECONTENT that provides hit and miss statistics on the cache)
  • RESET (reset the hit/miss statistics for either the provided cachename or group name, or for the entire cache)
cachenamerequired when action=cacheN/AThe name to assign to the cache being created.
groupoptionalCGI.SERVER_NAMEAn optional group name to assign to the cache.
cachedwithinoptionalN/AThe maximum time (specified using CreateTimeSpan() to pull from the cache before the cache is recreated.

Notes

CFCACHECONTENT provides a simple yet powerful way to cache rendered page content so it does not need to be generated each time it is requested. CFCACHECONTENT is essentially a combination of CFSAVECONTENT and CFCACHE but allows for much more granular control over caching. In addition, the cached data can be stored in either the server's RAM or in a database table.

The CACHENAME and GROUP attributes provide granular control over caching data and clearing the cached data. The STATS action provides a simple way of seeing how effective the caching is by providing hit and miss statistics for the cache.

By default, cache data is stored in server RAM, which means the cache will not persist server restarts. By adding a datasource value for CFCACHECONTENT to the bluedragon.xml file, however, the cached data can be stored in a database:

<server>
  <cfcachecontent>
    <datasource>datasource_name</datasource>
    <total>20</total>
  </cfcachecontent>
</server>

Note that this setting is not currently accessible via the OpenBD administrator, but it will be added to a future version.

When the cache is stored to the database, a table called LRUCACHE is created if it doesn't already exist. The <total> node indicates the number of items that are stored in memory before the database is used. All cache operations including flushes affect the database cache as well.

Usage

Cache the output between the CFCACHECONTENT tags with a name of "mycache" in the group "mygroup" for 20 minutes:

<cfcachecontent action="cache" cachename="mycache" group="mygroup" cachedwithin="#CreateTimeSpan(0,0,20,0)#">
  <cfoutput>#myCFC.getLotsOfData()#</cfoutput>
</cfcachecontent>

Flush the cache named "mycache":

<cfcachecontent action="flush" cachename="mycache">

Dump the stats for the entire cache:

<cfcachecontent action="stats">
<cfdump var="#CFCACHECONTENT#">

Personal tools