$cache
Updated on Aug 19, 2025 3 minutes to readThe Cache Plugin provides methods to store, retrieve, and manage values in a cache with optional expiration.
Methods
| Method | Description | 
|---|---|
| clear | Deletes all values from the cache. | 
| getItem | Retrieves a value from the cache by key. | 
| getOrSetItem | Retrieves a value by key or sets it using a callback if missing. | 
| hasItem | Checks whether a key exists in the cache. | 
| removeItem | Deletes a value from the cache by key. | 
| setItem | Stores a value in the cache with an optional expiration. | 
Methods Details
clear()
• Type
() => boolean• Details
Deletes all values from the cache.
Returns a boolean indicating whether the cache was successfully cleared.
getItem()
• Type
(key: string) => string | number | undefined• Details
Expects a string key identifying the cached value.
Returns the cached value as a string or number, or undefined if the key does not exist.
getOrSetItem()
• Type
(
    key: string,
    callback: () => string | number | false,
    duration?: number
) => string | number | false• Details
Expects a string key, a callback function returning a value to cache (or false to skip caching), and optional duration in seconds (default: 0). If duration is 0, the cached value is stored indefinitely.
Returns the cached value, the result of the callback, or false if the callback returned false.
• Example
const value = E8App.$cache.getOrSetItem('userScore', () => 42, 3600);
// value now contains the cached value or 42 if newly sethasItem()
• Type
(key: string) => boolean• Details
Expects a string key identifying the cached value.
Returns true if the key exists in the cache, otherwise false.
removeItem()
• Type
(key: string) => boolean• Details
Expects a string key identifying the cached value to remove.
Returns true if the key was successfully deleted, otherwise false.
setItem()
• Type
(
    key: string,
    value: string | number,
    duration?: number
) => boolean• Details
Expects a string key, a string or number value, and optional duration in seconds (default: 0). If duration is 0, the cached value is stored indefinitely.
Returns true if the value was successfully stored in the cache.