Session Cache Provider
The CServerSessionCache provider stores data on the server side, persisting data for the duration of a user session.
Note: Server-side caches use the memory of the server they are running on. They may not work as expected in a stateless environment.
CServerSessionCache provides server-side in-memory caching isolated per user session (using the user's session identifier). Like traditional server sessions (PHP-style), it persists across requests for that specific user session on stateful Node.js servers, and is never hydrated to the client.
import { CServerSessionCache } from '@katlux/providers'
const sessionCache = CServerSessionCache.getInstance()
// Only runs in the server session environment
await sessionCache.set('temp-wizard-data', { step: 2 }, 3600000)
const data = await sessionCache.get('temp-wizard-data')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 |