Description

Removes an object from the cache.

Returns

Nothing.

Category

Cache functions

Function syntax

CacheRemove(Object id, boolean throwOnError, String key, boolean exact)

See also

cfcacheCacheGetCachePutCacheGetAllIdsCacheGetPropertiesCacheGetMetadataCacheSetProperties

History

ColdFusion 11: The ids parameter will also accept an array.

ColdFusion 10: Added the parameters region and {{exact}}.

ColdFusion 9: Added the function.

Parameters

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.

key

(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.

Example with parameter exact set to 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>

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