Skip to Content
APIConfigurationClass: PersistentCache<T>

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

Constructors

Constructor

ICache

Parameters

config

CacheConfig

maxStorageBytes?

number

Returns

PersistentCache<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

The cache key to remove

Returns

boolean

true if the key was found and removed

Implementation of

ICache.delete


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

ICache.get


getStats()

PersistentCache

Returns current cache statistics

Returns

CacheStats

CacheStats object with size and configuration info

Implementation of

ICache.getStats


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

ICache.has


keys()

void

Returns all keys currently in the cache

Returns

string[]

Array of cache keys

Implementation of

ICache.keys


set()

ICache

Stores a value in the cache

Parameters

key

string

The cache key

value

T

The value to store

Returns

void

Implementation of

ICache.set

Last updated on