Skip to Content
APIConfigurationClass: LRUCache<T>

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

T

Type Parameters

T

T

The type of values stored in the cache

Implements

Constructors

Constructor

ICache

Parameters

config

CacheConfig

Returns

LRUCache<T>

Methods

clear()

T

Removes all entries from the cache

Returns

void

Implementation of

ICache.clear


delete()

CacheConfig

Removes a specific key from the cache

Parameters

key

string

Returns

boolean

Implementation of

ICache.delete


get()

LRUCache

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

ICache.get


getStats()

T

Returns cache statistics

Returns

CacheStats

Implementation of

ICache.getStats


has()

void

Checks if a key exists and is not expired

Parameters

key

string

Returns

boolean

Implementation of

ICache.has


keys()

ICache

Returns all keys in the cache

Returns

string[]

Implementation of

ICache.keys


set()

clear

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

ICache.set

Last updated on