User Guide Cancel

CacheRegionNew

 

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])
cacheRegionNew(region,[properties],[throwOnError])
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. For a list of all properties, see CacheSetProperties.

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

<cfscript>
defaultCacheProps = StructNew();
defaultCacheProps.maxElementsInMemory = "5";
defaultCacheProps.eternal = "false";
defaultCacheProps.timeToIdleSeconds= "100";
defaultCacheProps.timeToLiveSeconds= "50";
defaultCacheProps.overflowToDisk= "true";
defaultCacheProps.diskExpiryThreadIntervalSeconds= "3600";
defaultCacheProps.diskPersistent= "false";
defaultCacheProps.diskPoolBufferSizeMB= "30";
defaultCacheProps.maxElementsOnDisk= "10";
defaultCacheProps.memoryEvictionPolicy= "LRU";
defaultCacheProps.clearOnFlush= "true";
defaultCacheProps.objectType= "Object";
// create cache region
cacheRegionNew("testregion",defaultCacheProps,false)
// Defining a struct object
obj1 = StructNew()
obj1.name = "xyz"
timeToLive = CreateTimeSpan(0,0,5,0)
timeToIdle = CreateTimeSpan(0,0,10,0)
// Putting Cache in the USD specific cache
writeOutput("Starting to write to cache..")
cachePut("obj1",obj1,timetoLive,timeToIdle,"testregion")
writeOutput("Trying to fetch cached item...")
obj = cacheGet("obj1","testregion")
writeOutput(obj.name)
</cfscript>
<cfscript> defaultCacheProps = StructNew(); defaultCacheProps.maxElementsInMemory = "5"; defaultCacheProps.eternal = "false"; defaultCacheProps.timeToIdleSeconds= "100"; defaultCacheProps.timeToLiveSeconds= "50"; defaultCacheProps.overflowToDisk= "true"; defaultCacheProps.diskExpiryThreadIntervalSeconds= "3600"; defaultCacheProps.diskPersistent= "false"; defaultCacheProps.diskPoolBufferSizeMB= "30"; defaultCacheProps.maxElementsOnDisk= "10"; defaultCacheProps.memoryEvictionPolicy= "LRU"; defaultCacheProps.clearOnFlush= "true"; defaultCacheProps.objectType= "Object"; // create cache region cacheRegionNew("testregion",defaultCacheProps,false) // Defining a struct object obj1 = StructNew() obj1.name = "xyz" timeToLive = CreateTimeSpan(0,0,5,0) timeToIdle = CreateTimeSpan(0,0,10,0) // Putting Cache in the USD specific cache writeOutput("Starting to write to cache..") cachePut("obj1",obj1,timetoLive,timeToIdle,"testregion") writeOutput("Trying to fetch cached item...") obj = cacheGet("obj1","testregion") writeOutput(obj.name) </cfscript>
<cfscript>
    defaultCacheProps = StructNew();
    defaultCacheProps.maxElementsInMemory = "5";
    defaultCacheProps.eternal = "false";
    defaultCacheProps.timeToIdleSeconds= "100";
    defaultCacheProps.timeToLiveSeconds= "50";
    defaultCacheProps.overflowToDisk= "true";
    defaultCacheProps.diskExpiryThreadIntervalSeconds= "3600";
    defaultCacheProps.diskPersistent= "false";
    defaultCacheProps.diskPoolBufferSizeMB= "30";
    defaultCacheProps.maxElementsOnDisk= "10";
    defaultCacheProps.memoryEvictionPolicy= "LRU";
    defaultCacheProps.clearOnFlush= "true";
    defaultCacheProps.objectType= "Object";
    // create cache region
    cacheRegionNew("testregion",defaultCacheProps,false)
    // Defining a struct object
    obj1 = StructNew() 
    obj1.name = "xyz" 
    timeToLive = CreateTimeSpan(0,0,5,0)
    timeToIdle = CreateTimeSpan(0,0,10,0)
    // Putting Cache in the USD specific cache
    writeOutput("Starting to write to cache..")
    cachePut("obj1",obj1,timetoLive,timeToIdle,"testregion")
    writeOutput("Trying to fetch cached item...") 
    obj = cacheGet("obj1","testregion")
    writeOutput(obj.name)
</cfscript>

Get help faster and easier

New user?