Description

Creates a new custom cache region (if no cache region exists).

Returns

An error if throwOnError parameter is set to true, provided cache region already exists.

History

ColdFusion 10: Added this function.

Syntax

cacheRegionNew(region,[properties],[throwOnError]__)

Properties

Parameter

Description

region

Name of the new cache region to be created.

properties

Optional. Struct that contains the cache region properties.

throwOnError

Optional. A Boolean value specifying if to throw an exception if the cache region name you specify already exists. The default value is true.

Example

<!--- Defining properties for the struct ---> 
<cfset defaultCacheProps = StructNew()> 
<cfset defaultCacheProps.CLEARONFLUSH = "true"> 
<cfset defaultCacheProps.DISKEXPIRYTHREADINTERVALSECONDS = "3600"> 
<cfset defaultCacheProps.DISKPERSISTENT = "false"> 
<cfset defaultCacheProps.DISKSPOOLBUFFERSIZEMB = "30"> 
<cfset defaultCacheProps.ETERNAL = "false"> 
<cfset defaultCacheProps.MAXELEMENTSINMEMORY = "5"> 
<cfset defaultCacheProps.MAXELEMENTSONDISK = "10"> 
<cfset defaultCacheProps.MEMORYEVICTIONPOLICY = "LRU"> 
<cfset defaultCacheProps.OBJECTTYPE = "OBJECT"> 
<cfset defaultCacheProps.OVERFLOWTODISK = "true"> 
<cfset defaultCacheProps.TIMETOLIVESECONDS = "5"> 
<cfset defaultCacheProps.TIMETOIDLESECONDS = "30"> 
<cfset cacheRegionNew("testregion",#defaultCacheProps#,false)> 
<!--- Defining a struct object ---> 
<cfset obj1 = structNew()> 
<cfset obj1.name = "xyz"> 
<cfset timeToLive = CreateTimeSpan(0,0,5,0)> 
<cfset timeToIdle = CreateTimeSpan(0,0,10,0)> 
<!--- Putting Cache in the USD specific cache ---> 
<cfoutput>Starting to write to cache..</cfoutput> 
<cfset cachePut("obj1",obj1,timetoLive,timeToIdle,"testregion")> 

<cfoutput>Trying to fetch cached item...</cfoutput> 
<cfset obj = cacheGet("obj1","testregion")> 
<br/> 
<cfoutput>Done!!<br></cfoutput> 
<cfoutput>#obj.name#</cfoutput>

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