cacheGet

Gets an object that is stored in the cache.

cacheGet(id [,region]) → returns The object stored in the cache, or undefined/null. Use isNull() to check.

cacheGet Argument Reference

id
Required

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

region

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

cacheName

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

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


Simple Example

Puts an element in the cache and then retreives 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


Script Syntax - Named Cache

Puts an element in a named cache and then retreives it. CF 10+ Lucee 4.5+

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

Expected Result: The cow says moo


Fork me on GitHub