LocalStorage Cache Provider
The CLocalStorageCache provider stores data synchronously in the browser's LocalStorage API. It is ideal for persistent, string-based cache on the client side.
Data stored in LocalStorage persists across browser sessions. Be mindful of the 5MB domain limit.
import { CLocalStorageCache } from '@katlux/providers'
const lsCache = CLocalStorageCache.getInstance()
// Only runs in the browser environment
await lsCache.set('user-settings', { theme: 'dark' }, 31536000000) // 1 year
const data = await lsCache.get('user-settings')Configuration options passed when initializing the provider
| Property | Type | Description |
|---|
| getInstance() | Singleton Method | This provider utilizes the Singleton pattern and takes no constructor parameters. |
Standard methods inherited from ACacheProvider
| Method | Parameters | Returns | Description |
|---|
| get<T> | key: string, nuxtApp?: any | Promise<T | null> | Retrieves the cached data if it exists and hasn't expired |
| set<T> | key: string, data: T, lifetime: number, nuxtApp?: any | Promise<void> | Stores the data with the specified lifetime in milliseconds |
| remove | key: string, nuxtApp?: any | Promise<void> | Removes a specific key from the cache |
| removeByPrefix | prefix: string, nuxtApp?: any | Promise<void> | Removes all keys starting with the specified prefix |
| getKeyList | nuxtApp?: any | Promise<Array<string>> | Returns a list of all active cache keys |
| getRemainingTime | key: string, nuxtApp?: any | Promise<number | null> | Returns the remaining lifetime of a key in milliseconds |
| cleanupExpired | | Promise<void> | Forces cleanup of all expired cache entries |