Application Cache Provider
The CApplicationCache provider stores data on the server side using the memory space of the Node application/Nitro server. It is exclusively for server-side operations and persists until the server restarts.
Note: Server-side caches use the memory of the server they are running on. They may not work as expected in a stateless environment.
Application Cache is ideal for global server-side data (such as main page product lists or category trees) that should be shared across all visitors on the Node.js server. It persists until expiration or server restart, and is never hydrated to the client.
import { CApplicationCache } from '@katlux/providers'
const appCache = CApplicationCache.getInstance()
// Only runs in the server environment
await appCache.set('server-key', { config: true }, 3600000)
const data = await appCache.get('server-key')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 |