Class: PersistentCache<T>
Persistent Cache implementation (Decorator pattern) Wraps LRUCache with localStorage persistence.
Features:
- Automatic save to localStorage on modifications
- Hydration from localStorage on initialization
- Graceful degradation when localStorage unavailable
- Storage quota management
- Expired items filtered during hydration
Example
T
Type Parameters
T
T
The type of values stored in the cache
Implements
ICache<T>
Constructors
Constructor
ICache
Parameters
config
maxStorageBytes?
number
Returns
PersistentCache<T>
Methods
clear()
T
Removes all entries from the cache
Returns
void
Implementation of
delete()
CacheConfig
Removes a specific key from the cache
Parameters
key
string
The cache key to remove
Returns
boolean
true if the key was found and removed
Implementation of
get()
number
Retrieves a value from the cache
Parameters
key
string
The cache key
Returns
undefined | T
The cached value or undefined if not found/expired
Implementation of
getStats()
PersistentCache
Returns current cache statistics
Returns
CacheStats object with size and configuration info
Implementation of
has()
T
Checks if a key exists in the cache
Parameters
key
string
The cache key
Returns
boolean
true if the key exists and is not expired
Implementation of
keys()
void
Returns all keys currently in the cache
Returns
string[]
Array of cache keys
Implementation of
set()
ICache
Stores a value in the cache
Parameters
key
string
The cache key
value
T
The value to store
Returns
void