CacheDelete()
Deletes a single element from the cache.
CacheDelete( id=object, throwOnError=boolean, cacheName=string );
Returns: void
| Argument | Description |
|---|---|
|
id
object,
required
|
edit
the id of the element to delete, can also contain a "," (not used as separator) Alias: name, key |
|
throwOnError
boolean,
optional
|
edit
define if the functions throws an exception when the element does not exist. Default is false. |
|
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'
}}#";
cacheClear();
cachePut( "user:1", "Alice" );
cachePut( "user:2", "Bob" );
dump( cacheCount() ); // 2
// delete a single entry by id
cacheDelete( "user:1" );
dump( cacheCount() ); // 1
// by default, deleting a non-existent key is silently ignored
cacheDelete( "doesNotExist" );
// pass throwOnError=true to throw when the key doesn't exist
try {
cacheDelete( "doesNotExist", true );
} catch ( any e ) {
dump( e.message );
}
See also
- Cache
- Getting Started with Caching
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)