cachePut

Stores an object in the cache.

cachePut(id, value [, timespan] [, idleTime] [, region] [, throwOnError]) → returns void

Argument Reference

id string
Required

Unique identifier for the cached value

value any
Required

The value to cache

timespan date

The interval until the object is flushed from the cache, as a decimal number of days. One way to set the value is to use the return value from the CreateTimeSpan function. The default is to not time out the object.

idleTime date

A decimal number of days after which the object is flushed from the cache if it is not accessed during that time. One way to set the value is to use the return value from the CreateTimeSpan function.

region string

Lucee 4.5+ CF 10+ Specifies the cache region/name where you place the cache object.

throwOnError boolean
Default: false

CF 10+ If true and region does not exist, throws an error

Examples
Sample code invoking the cachePut function

<cfset cachedData = cacheGet("wt-6-cache")>
<!--- If the data is not cached, create it and do a cache put. --->
<cfif isNull(cachedData)>
	Cache doesn't exist, so create it.<br />
	<cfset sleep(1000)>
	<cfset cachedData = "This date/time IS cached: #now()#<br />">
	<cfoutput>#cachedData#</cfoutput> 
	<cfset cachePut("wt-6-cache", cachedData, createTimespan(0,0,0,10))>
</cfif>

I place data into the default cache.

// generate some data to cache
data = { bar = 'foo', foo = 'bar' };

// add the data to a named cache
cachePut( 'cached_object_name_or_id', data, createTimeSpan( 0, 0, 30, 0 ), createTimeSpan( 0, 0, 15, 0 ) );

I place data into a named cache. CF 10+ Lucee 4.5+

// generate some data to cache
data = { bar = 'foo', foo = 'bar' };

// add the data to a named cache
cachePut( 'cached_object_name_or_id', data, createTimeSpan( 0, 0, 30, 0 ), createTimeSpan( 0, 0, 15, 0 ), 'region_cacheName' );

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

Fork me on GitHub