Removes one or more objects from the cache.
Nothing.
CacheRemove(id, [boolean throwOnError, String region, boolean exact])
cfcache, CacheGet, CachePut, CacheGetAllIds, CacheGetProperties, CacheGetMetadata, CacheSetProperties
ColdFusion (2018 release): Renamed the parameter key to region.
ColdFusion 11: The ids parameter will also accept an array.
ColdFusion 10: Added the parameters region and {{exact}}.
ColdFusion 9: Added the function.
Parameter |
Description |
|---|---|
id |
A comma delimited string of IDs of the cached objects to remove. Starting from ColdFusion 11, you can also specify an array of IDs. |
throwOnError |
(Optional) A Boolean value specifying whether to throw an exception if any ID does not specify a cached element. The default value is false. |
region |
(Optional) Name of the cache region from which to remove the cached objects. |
exact |
(Optional) If true, the search narrows down to values that exactly match the IDs (for removal). The default value is true. |
<cfscript>
// get all cache ids of cache region, myRegion
Writedump(cacheGetAllIds("myRegion",true));
//array of all cache ids are below:
// CACHE_1
// CACHE_3
// CACHE_2
// when exact=true, does not remove any objects, as no ids match
CacheRemove("cache",true,"myRegion",true);
Writeoutput("All cache ids are");
try{
Writedump(cacheGetAllIds("myRegion"));
}
catch(any e){
WriteOutput("Error: " & e.message);
}
</cfscript>
Example with parameter exact set to false
<cfscript>
// get all cache ids of cache region, myRegion
Writedump(cacheGetAllIds ("myRegion",true));
//array of all cache ids are below:
// CACHE_1
// CACHE_3
// CACHE_2
// when exact=false, removes all objects with partially matching ids
CacheRemove("cache",true,"myRegion",false);
Writeoutput("All cache ids are");
Writedump(cacheGetAllIds ("myRegion"));
</cfscript>
Sign in to your account