CacheClear()

edit

Flushes a cache

CacheClear( filterOrTags=any, cacheName=string );

Returns: Number

Argument Description
filterOrTags
any, optional
edit

You can define 2 different things here:

  1. a String containing a key filter for the elements in the cache to flush, the filter follow the same rules as for <cfdirectory>-filter.
  2. an Array containing tags defined when put the element to the cache

Alias: filter, tags, tag

cacheName
string, optional
edit

definition of the cache used by name, when not set the "default Object Cache" defined in Lucee Administrator is used instead.

Alias: cache, region

Examples

edit
// define a RAM cache as the default object cache
application action="update" caches="#{ trycf: {
	class: 'lucee.runtime.cache.ram.RamCache',
	custom: { timeToIdleSeconds: 3600, timeToLiveSeconds: 3600 },
	default: 'object'
}}#";
// store some values
cachePut( "fruit:apple", "red" );
cachePut( "fruit:banana", "yellow" );
cachePut( "vehicle:car", "blue" );
dump( cacheCount() ); // 3
// clear only keys matching a wildcard filter
cacheClear( "fruit:*" );
dump( cacheCount() ); // 1 — only vehicle:car remains
// clear everything
cacheClear();
dump( cacheCount() ); // 0

See also