cacheRemove

Removes an object from the cache.

cacheRemove(ids [, throwOnError [, key[, exact]]]) → returns void

cacheRemove Argument Reference

ids
Required

Comma delimited list of cache IDs. A list of all available IDs can be retrieved using cacheGetAllIds. CF 11+ Can take an array instead of a list.

throwOnError
Default: NO

true throws an error when cache ID does not exist.

key

CF 10+ Specify which cache region to search

exact
Default: YES

CF 10+ Used to partially match on keys

Examples sample code invoking the cacheRemove function


Remove one ID using exact match

cacheRemove( 'myCachedQuery' );

Example using exact=false

Remove using partially matching IDs

cachePut( 'cache_1', 'test data', 1000, 1000, 'test' );
cachePut( 'cache_2', 'test data', 1000, 1000, 'test' );

// this removes both cached objects:
cacheRemove( 'cache', false, 'test', false );

Example using exact=true

With exact set to true, no IDs match, so none will be deleted

cachePut( 'cache_1', 'test data', 1000, 1000, 'test' );
cachePut( 'cache_2', 'test data', 1000, 1000, 'test' );

// this removes no object:
cacheRemove( 'cache', false, 'test', true );

Remove all cached data using default settings

(ColdFusion 10 added cacheRemoveAll.)

<cfset allCacheIDs = cacheGetAllIds( ) />
<cfif not arrayIsEmpty( allCacheIDs )>
  <cfset cacheRemove( allCacheIDs ) />
</cfif>

Fork me on GitHub