Skip to main content

Recipes

Switch to the file driver

CACHE_DRIVER=file
CACHE_FILE_FOLDER=.cache

Switch to Redis

CACHE_DRIVER=redis
CACHE_REDIS_HOST=127.0.0.1
CACHE_REDIS_PORT=6379
CACHE_REDIS_DB=0
CACHE_REDIS_KEY_PREFIX=quik:cache:

Install the ioredis peer dependency when using the Redis driver.

Bring your own backend

Implement IQCache and register it through the core feature registry instead of relying on a built-in driver:

import { initFeature } from '@quik/core';
import type { IQCache } from '@quik/cache';

class MemcachedCache 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 MemcachedCache());

Checklist

  • Register @quik/cache in bootstrap before any code calls getCache().
  • Set cache.defaultTtlMs if you want a non-zero default expiry.
  • Custom backends replace the IQCache feature entirely — module setup is not required when you register your own.