Description

Stores an object in the cache.

Returns

Nothing

Category

Cache functions

Function syntax

CachePut(id, value, [timeSpan], [idleTime], [region], [throwOnError])

See also

cfcacheCacheGetCacheGetAllIdsCacheGetPropertiesCacheRemoveCacheSetProperties

History

ColdFusion 10: Added the region and throwOnError parameters.ColdFusion 9: Added the function.

Parameters

Parameter

Description

id

The ID for the cache object.

value

The value of the object. Can be any data type supported by ColdFusion

timeSpan

(Optional) 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

(Optional) 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

Optional. Specifies the cache region where you can place the cache object.

throwOnError

Optional. If True and if regen does not exist, throws an error.

 

Example

<cfscript>
       //define a cache region struct
       rProps={};
       // define properties for region struct
       rProps.MAXELEMENTSINMEMORY = "5";
       rProps.ETERNAL = "false";
       rProps.TIMETOIDLESECONDS = "100";
       rProps.TIMETOLIVESECONDS = "50";
       rProps.OVERFLOWTODISK = "true";
       rProps.DISKEXPIRYTHREADINTERVALSECONDS = "3600";
       rProps.DISKPERSISTENT = "false";
       rProps.DISKSPOOLBUFFERSIZEMB = "30";
       rProps.MAXELEMENTSONDISK = "10";
       rProps.MEMORYEVICTIONPOLICY = "LRU";
       rProps.CLEARONFLUSH = "true";
       rProps.OBJECTTYPE = "OBJECT";
       // create a cache region, kRegion, that contains the properties defined above
       CacheRegionNew("cRegion",#rProps#,true);
       // display the properties of the newly created cache region
       WriteDump(CacheGetProperties("cRegion"));
       // store an object in the cache cpRegion
       // create object myObj
       myObj={};
       myObj.a="hello";
       myObj.b="world";
       // store myObj in the cache region
CachePut("id_1",myObj,createTimespan(0,0,30,0),createTimespan(0,0,15,0),"cRegion");
       // display the contents of the cache
       Writedump(CacheGet("id_1","cRegion"));
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy