cachePut

Stores an object in the cache.

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

Argument Reference for the cachePut function

id

Required: Yes
Unique identifier for the cached value

value

Required: Yes
The value to cache

timespan

Required: No
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

Required: No
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

Required: No
CF 10+ Specifies the cache region where you can place the cache object. Applies only to ACF.

cacheName

Required: No
Lucee 4.5+ Definition of the cache used by name. Applies only to Lucee.

Examples sample code invoking the cachePut function


Tag Syntax

<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>  

Script Syntax

I place data into the default cache.

<cfscript>
// 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 ) );
</cfscript>

Script Syntax - Named Cache

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

<cfscript>
// 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' );
</cfscript>

Fork me on GitHub