cache()
Usage
cache(key, timeout, valueExpression)
Description
This method can be used to store a value (which is costly to obtain or should be updated frequently) under the given key in a global cache. The method will execute the given valueExpression to obtain the value, and store it for the given time (in seconds). All subsequent calls to the cache()
method will return the stored value (until the timeout expires) instead of evaluating the valueExpression
.
Example
${cache('externalResult', 3600, GET('http://api.myservice.com/get-external-result'))}
${{
Structr.cache('myCacheKey', 3600, 'initialCacheValue');
Structr.cache('myCacheKey', 3600, 'test test test');
Structr.log(Structr.cache('myCacheKey', 3600, 'test 2 test 2 test 2'));
}}
will log initialCacheValue
to the server log.
To have more granular control over cache entries, see the related cache functions.