Pluggable cache backend. The default is an in-memory LRU; implement this interface to back the cache with Redis, Cloudflare KV, or anything else. All methods may be async so remote stores work transparently.
const store: CacheStore = { async get(key) { const v = await redis.get(key); return v ? JSON.parse(v) : undefined }, async set(key, value, ttlMs) { await redis.set(key, JSON.stringify(value), 'PX', ttlMs) }, async delete(key) { await redis.del(key) },}const cache = createHoodCache(hood, { store }) Copy
const store: CacheStore = { async get(key) { const v = await redis.get(key); return v ? JSON.parse(v) : undefined }, async set(key, value, ttlMs) { await redis.set(key, JSON.stringify(value), 'PX', ttlMs) }, async delete(key) { await redis.del(key) },}const cache = createHoodCache(hood, { store })
Optional
Pluggable cache backend. The default is an in-memory LRU; implement this interface to back the cache with Redis, Cloudflare KV, or anything else. All methods may be async so remote stores work transparently.
Example: A Redis adapter (ioredis)