Output Caching
The cf_spCacheThis tag can be used in Speck applications to eliminate unnecessary data access and improve processing times by caching previously generated output in memory.
The tag must be used with an end tag to define a block of code whose output is to be cached. When cf_spCacheThis is wrapped around a block of output, the first time the output is requested the tag allows the code to run normally and then caches the resulting output. For future requests, cf_spCacheThis will output the previously saved output, without having to run the nested code again. Simple.
Note: content displayed will not come from the cache when the site is being viewed at a level other than "live" or with administration links enabled. Not only that, but caches get flushed when content is added or modified, so you cannot rely on all items being requested to be retrieved from the cache. Your pages still need to respond adequately without caching or not only will your admin users be very unhappy, but your visitors will also have to deal with the slow loading pages when the output has not already been cached.
cf_spCacheThis tag syntax
<cf_spCacheThis
cacheName="unique name to identify cache"
cacheExpires="date or number of minutes from now"
persistent="yes|no">
... code whose output is to be cached
</cf_spCacheThis>
The following table list the attributes of the cf_spApp tag:
| Attribute | Type | Required | Description |
|---|---|---|---|
| cacheName | String | Yes | Unique name used to identify this cache. Must be a valid ColdFusion variable name as this value is used as the name of a structure created in application scope to store information about this cache. |
| cacheExpires | Number or Date | No | Number of minutes from now that cache should expire, or specific datetime that cache should expire. Caches never expire by default. |
| persistent | Boolean | No | Cache the generated output in persistent storage as well as in memory. At the moment this basically means a copy of the cached output is saved to the database. This allows the cfserver to be restarted and the in-memory caches to be rebuilt from the persistent cache. The default value is the value of the persistentOutputCache application configuration setting, the default value for which is "yes". |
Flushing output caches
Speck does its best to manage the caches so when content is added or modified on the live site, caches that might display any properties from that content item are flushed, to be recreated the next time the pages containing the caches are requested. This works fine as long as you use the id, label or keywords attributes of the cf_spContent[Get] tag when retrieving content items - Speck tracks which content items have been cached according to the values of these attributes.
If the id, label or keywords attributes are not used when retrieving content, Speck does not track the content items that have been cached. In situations like this, you should use the cacheExpires attribute to be sure the caches will expire at some point.
Ok, ok, it is a little more complicated than that. The cache will be flushed if the cf_spCacheThis tag contains the call to cf_spContent that generated the administration links used to add or modify the content, but this shouldn't really be relied upon because the same content item may appear in multiple locations on a web site.