ACacheProvider Abstract Class
The foundational abstract system mapping caching functions universally shared by Client-Side and Server-Side instances.
Constructor Constraints
Inherited directly by singletons like Cookie Cache Provider and custom cache drivers. It strictly requires explicit override integration methods managing standard caching lifecycles automatically mapping lifetimes and `nuxtApp` environment bindings safely.
TypeScript
import { ACacheProvider, CacheProviderFactory, type ICacheEntry } from '@katlux/providers'
export class CMyCustomCache extends ACacheProvider {
private static instance: CMyCustomCache | null = null
private storage = new Map<string, ICacheEntry<any>>()
public static getInstance(): CMyCustomCache {
if (!this.instance) this.instance = new CMyCustomCache()
return this.instance
}
async getKeyList(nuxtApp?: any): Promise<string[]> {
return Array.from(this.storage.keys())
}
async get<T>(key: string, nuxtApp?: any): Promise<T | null> {
const entry = this.storage.get(key)
if (!entry) return null
if (Date.now() > entry.timestamp + entry.lifetime) {
this.storage.delete(key)
return null
}
return entry.data as T
}
async set<T>(key: string, data: T, lifetime: number, nuxtApp?: any): Promise<void> {
this.storage.set(key, { data, timestamp: Date.now(), lifetime })
}
async remove(key: string, nuxtApp?: any): Promise<void> {
this.storage.delete(key)
}
async removeByPrefix(prefix: string, nuxtApp?: any): Promise<void> {
for (const key of this.storage.keys()) {
if (key.startsWith(prefix)) this.storage.delete(key)
}
}
async getRemainingTime(key: string, nuxtApp?: any): Promise<number | null> {
const entry = this.storage.get(key)
if (!entry) return null
const remaining = (entry.timestamp + entry.lifetime) - Date.now()
return remaining > 0 ? remaining : null
}
async cleanupExpired(): Promise<void> {
const now = Date.now()
for (const [key, entry] of this.storage.entries()) {
if (now > entry.timestamp + entry.lifetime) this.storage.delete(key)
}
}
}
// Register with the factory:
CacheProviderFactory.registerDriver('MyCustom', CMyCustomCache)Abstract Definition structure
Implemented by Katlux Katlux providers locally. All methods accept an optional `nuxtApp` payload binding context.
| Method Signature |
|---|
|
|
|
|
|
|
|
Related Base Classes & Types
| Symbol | Category | Description |
|---|---|---|
| ADataProvider | Base Class | Foundational abstract class for flat and tree data providers |
| AEncryptionProvider | Base Class | Foundational abstract class for payload encryption providers |
| ECacheStrategy | Enum | Built-in cache backends enumeration |
| ICacheEntry | Interface | Storage envelope schema for cached values |
| Custom Cache Strategy Guide | Guide | Step-by-step walkthrough for extending ACacheProvider |