cacheGet

Gets an object that is stored in the cache.

cacheGet(id [,region]) → returns any

Argument Reference

id string
Required

The ID value assigned to the cache object when it was created

region string

CF 10+ The name of the cache region where the object was stored. Applies only to ACF.

cacheName string

Lucee 4.5+ The name of the cache where the object was stored. Applies only to Lucee.

throwWhenNotExist boolean
Default: false

Lucee 4.5+ Enable/Disable throwing an error if element not exists

Compatibility

Lucee:

For Lucee the method signature is: cacheGet( id [, throwWhenNotExist [, cacheName ] ] ) however it does support passing a cacheName in as the second argument for compatibility with ACF.

Examples
Sample code invoking the cacheGet function

Puts an element in the cache and then retrieves it.

cowSays = cacheGet( "cow" );
if ( isNull( cowSays ) ) {
    cowSays = "moo";
    cachePut( "cow", cowSays, createTimeSpan( 0, 0, 30, 0 ), createTimeSpan( 0, 0, 15, 0 ) );
}
writeOutput( "The cow says " & cowSays );

Expected Result: The cow says moo

CF 10+ Puts an element in a named cache and then retrieves it.

cacheID = "cow";
timespan = createTimeSpan(0, 0, 30, 0);
idleTime = createTimeSpan(0, 0, 15, 0);
regionName = "region_cacheName";
cowSays = cacheGet(cacheID, regionName);
if (isNull(cowSays)) {
    cowSays = "moo";
     cachePut(cacheID, cowSays, timespan, idleTime, regionName);
}
writeOutput("The cow says #cowSays#.");

Expected Result: The cow says moo.

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub