User Guide Cancel

CacheRemoveAll

 

Description

Removes all stored objects in a cache region. If no cache region is specified, objects in the default region are removed.

Returns

Nothing

History

ColdFusion 10: Added this function.

Syntax

cacheRemoveAll(region)
cacheRemoveAll(region)
cacheRemoveAll(region)

Properties

Parameter

Description

region

(Optional) Indicates the cache region from which to remove the stored objects. If no value is specified, default cache region is considered by default.

Example

<cfscript>
// create cache region with no properties
rProps={};
CacheRegionNew("newRegion",rProps,true);
// create cache timespan and idle time
timeToLive = CreateTimeSpan(0, 0, 30, 0);
timeToIdle = CreateTimeSpan(0, 0, 30, 0);
// define objects to be inserted into cache region
foo1=foo2=foo3={};
// populate cache with values
cachePut("1", "foo1", timeToLive, timeToIdle, "newRegion");
cachePut("2", "foo2", timeToLive, timeToIdle, "newRegion");
cachePut("3", "foo3", timeToLive, timeToIdle, "newRegion");
WriteOutput("Before cacheRemove() :: Number of objects in the cache:" & ArrayLen(cacheGetAllIds("newRegion")));
//clear all objects from the cache
cacheRemoveAll("newRegion");
WriteOutput("After cacheRemove() :: Number of objects in the cache:" & ArrayLen(cacheGetAllIds("newRegion")));
</cfscript>
<cfscript> // create cache region with no properties rProps={}; CacheRegionNew("newRegion",rProps,true); // create cache timespan and idle time timeToLive = CreateTimeSpan(0, 0, 30, 0); timeToIdle = CreateTimeSpan(0, 0, 30, 0); // define objects to be inserted into cache region foo1=foo2=foo3={}; // populate cache with values cachePut("1", "foo1", timeToLive, timeToIdle, "newRegion"); cachePut("2", "foo2", timeToLive, timeToIdle, "newRegion"); cachePut("3", "foo3", timeToLive, timeToIdle, "newRegion"); WriteOutput("Before cacheRemove() :: Number of objects in the cache:" & ArrayLen(cacheGetAllIds("newRegion"))); //clear all objects from the cache cacheRemoveAll("newRegion"); WriteOutput("After cacheRemove() :: Number of objects in the cache:" & ArrayLen(cacheGetAllIds("newRegion"))); </cfscript>
<cfscript>
       // create cache region with no properties
       rProps={};
       CacheRegionNew("newRegion",rProps,true);
       // create cache timespan and idle time
       timeToLive = CreateTimeSpan(0, 0, 30, 0);
       timeToIdle = CreateTimeSpan(0, 0, 30, 0);
       // define objects to be inserted into cache region
       foo1=foo2=foo3={};
       // populate cache with values
       cachePut("1", "foo1", timeToLive, timeToIdle, "newRegion");
       cachePut("2", "foo2", timeToLive, timeToIdle, "newRegion");
       cachePut("3", "foo3", timeToLive, timeToIdle, "newRegion");
       WriteOutput("Before cacheRemove() :: Number of objects in the cache:" & ArrayLen(cacheGetAllIds("newRegion")));
       //clear all objects from the cache
       cacheRemoveAll("newRegion");
       WriteOutput("After cacheRemove() :: Number of objects in the cache:" & ArrayLen(cacheGetAllIds("newRegion")));
</cfscript>
Caution:

If you have created your own cache regions, remove them accordingly to avoid memory leaks.

Get help faster and easier

New user?