Quik Framework :: Cache
- Codename: Berlin
- Version: 0.2.0-beta.76
- License: Check license here
Provides a pluggable caching abstraction built on the framework's feature
system. Ships with an in-memory implementation that supports per-entry TTLs.
Replace it with any backend (Redis, Memcached, etc.) by registering a custom
IQCache implementation through the core feature registry.
Installation
pnpm add @quik/cache
Usage
Basic get/set
import { getCache } from '@quik/cache';
const cache = getCache();
await cache.set('user:1', { name: 'Alice' }, 60_000); // 60 s TTL
const user = await cache.get<{ name: string }>('user:1');
if (await cache.has('user:1')) {
await cache.delete('user:1');
}
await cache.clear(); // wipe all entries
Module setup
Call Module.setup() during bootstrap to register the in-memory cache as the
active IQCache feature:
import { Module as CacheModule } from '@quik/cache';
await CacheModule.setup({ /* bootstrap options */ });
Custom backend
import { initFeature } from '@quik/core';
import type { IQCache } from '@quik/cache';
class RedisCache implements IQCache {
async get<T>(key: string): Promise<T | undefined> { /* … */ }
async set<T>(key: string, value: T, ttlMs?: number): Promise<void> { /* … */ }
async delete(key: string): Promise<void> { /* … */ }
async has(key: string): Promise<boolean> { /* … */ }
async clear(): Promise<void> { /* … */ }
}
initFeature('IQCache', new RedisCache());
Configuration
cache.defaultTtlMs— default TTL applied when nottlMsis passed toset().0means no expiry (default).
API Highlights
getCache()— returns the activeIQCacheinstance (from@quik/core).QInMemoryCache— Map-backed implementation with lazy TTL eviction.IQCache— interface to implement for custom backends.
Testing & Coverage
See the root instructions for details on running pnpm run test:coverage and accessing coverage artifacts.
API Reference
Generated API documentation is available in the cache API section.