api:cache
Version 23.0.9145
Version 23.0.9145
api:cache
Use the api:cache
keyword to cache the output of a script or a template. Caching helps throttle the execution of resource-intensive scripts whose output is not expected to change. You can cache the output to a file for a specified duration or cache the output in memory. You can use priority-based or time-based caching.
Parameters
- file: The name of the file to which the output is cached. To cache to a file, you must also specify the
duration
ordependency
parameter. To cache different versions of output for different input parameter values, include the parameter values in the file name. - key: The key used to store the output of a script in an in-memory cache. To cache in memory, you must specify the
key
parameter. Like thefile
attribute, you can use script variables to differentiate between cache objects. - duration: The duration, in minutes. Use this to cache for a fixed time and then refresh the contents of an object cached in memory or a file.
- priority: The priority to use while caching to an in-memory cache. Only valid if
key
is specified. Valid values areLow
,BelowNormal
,Normal
,AboveNormal
,High
, andNotRemovable
. - update: Whether the
api:cache
statement refreshes the cache on invocation. The default isfalse
. - format: The cache file format:
SQLite
orRSS
. The default isRSS
. - table: The table in the SQLite database where the output is cached.
- dependency: The mapping to the ASP.NET cache dependency. When the specified file changes, the object in the cache is removed. This file or directory maps to
System.Web.Caching.CacheDependency(fileOrDir)
.
Control Attributes
None
Examples
Create an XML file for each customer type. The tofilename
formatter is used to ensure that the resulting name can be used as a file name:
<api:cache duration="10" file="cache_[customer_type |tofilename].xml"/>
Cache customer_type
records in memory, instead of to a file:
<api:cache priority="Normal" key="cache_[customer_type]"/>
Create a new cache object for each state specified in the request:
<api:cache key="cache_[_request.state]"/>