Class: LRUCache<T>
LRU (Least Recently Used) Cache implementation Implements the ICache interface with:
- Configurable capacity limits
- TTL-based expiration
- LRU eviction policy
- Hit rate tracking
Example
const cache = new LRUCache<string>({ maxItems: 100, ttlMs: 60000 })
cache.set("key1", "value1")
const value = cache.get("key1") // "value1"Type Parameters
T
T
The type of values stored in the cache
Implements
ICache<T>
Constructors
Constructor
new LRUCache<T>(config): LRUCache<T>;Parameters
config
Returns
LRUCache<T>
Methods
clear()
clear(): void;Removes all entries from the cache
Returns
void
Implementation of
delete()
delete(key): boolean;Removes a specific key from the cache
Parameters
key
string
Returns
boolean
Implementation of
get()
get(key): undefined | T;Retrieves a value from the cache Updates access time for LRU tracking Returns undefined if key doesn’t exist or is expired
Parameters
key
string
Returns
undefined | T
Implementation of
getStats()
getStats(): CacheStats;Returns cache statistics
Returns
Implementation of
has()
has(key): boolean;Checks if a key exists and is not expired
Parameters
key
string
Returns
boolean
Implementation of
keys()
keys(): string[];Returns all keys in the cache
Returns
string[]
Implementation of
set()
set(key, value): void;Stores a value in the cache Evicts LRU item if at capacity Refreshes TTL for existing keys
Parameters
key
string
value
T
Returns
void
Implementation of
Last updated on