ECacheStrategy Enum
Selects the cache storage backend used by the RequestProvider and data providers. Pass a value to the cacheStrategy constructor option or IRequestOptions to enable caching for API responses.
Usage Examples
Set a cache strategy on a data provider or a single request.
TypeScript
import { CAPIFlatServerDataProvider } from '@katlux/providers/data'
import { RequestProvider } from '@katlux/providers/request'
import { ECacheStrategy } from '@katlux/providers'
// 1. Provider-level caching (applies to all requests made by the provider)
const provider = new CAPIFlatServerDataProvider({
cacheStrategy: ECacheStrategy.Memory, // volatile, cleared on page reload
cacheLifetime: 30000 // 30 second TTL
})
// 2. Per-request override via RequestProvider
const rp = new RequestProvider()
// Cache in browser LocalStorage (survives page reload)
const config = await rp.registerRequest('/api/config', {
cacheStrategy: ECacheStrategy.LocalStorage,
lifetime: 86400000 // 24 hours
})
// Cache in IndexedDB (async, survives reload, larger capacity)
const bigData = await rp.registerRequest('/api/large-dataset', {
cacheStrategy: ECacheStrategy.IndexedDB,
lifetime: 3600000 // 1 hour
})
// Server-side: Application cache (shared across all requests globally)
// Use inside Nuxt server routes or API handlers
const serverData = await rp.registerRequest('/api/server-data', {
cacheStrategy: ECacheStrategy.Application,
lifetime: 60000
})
// Cookie cache (available on both client and server)
const cookieCached = await rp.registerRequest('/api/preferences', {
cacheStrategy: ECacheStrategy.Cookie,
lifetime: 604800000 // 7 days
})Strategies
| Value | Runtime | Persistence | Description |
|---|---|---|---|
| Memory | Client | Session only | Stores cache in JavaScript heap. Fast, but cleared on page reload or navigation. |
| LocalStorage | Client | Persistent | Stores cache in browser LocalStorage. Survives page reloads. Synchronous API. |
| IndexedDB | Client | Persistent | Stores cache in browser IndexedDB. Survives reloads. Asynchronous, higher capacity. |
| Cookie | Client + Server | Configurable | Stores cache in browser cookies. Accessible on both client and server (SSR). |
| Application | Server | Process lifetime | Stores cache in server process memory. Shared across all concurrent requests. Cleared on server restart. |
| Session | Server | Per-connection | Stores cache scoped to a specific server connection/session. |