Databasev0.1.10
@tekir/cache
Multi-driver cache: memory, Redis, and database stores, plus an HTTP response cache middleware.
Installation
$
bun add @tekir/cacheFeatures
- Multi-driver: memory, Redis, database
- get/set/has/delete/flush API
- getOrSet with lazy loading factory
- pull() to get and delete in one call
- TTL support with configurable defaults
- Store switching at runtime via store()
- HTTP response cache middleware with ETag and 304 support
Quick Example
TypeScript
import { Cache, cache, MemoryCacheStore } from '@tekir/cache'
const store = new Cache({ stores: { memory: new MemoryCacheStore() } })
router.get('/api/posts',
cache({ store, ttl: 60 }),
async () => Post.all())Changelog
v0.1.10LatestSeptember 16, 2026
- HTTP caching now preserves binary bodies and response status, isolates host and credential variants, and refuses private, no-store, error, empty, and cookie-setting responses.
- Published output now uses the shared Node-targeted ESM bundle pipeline with external dependencies and generated TypeScript declarations, while Bun consumers keep the native source export.
v0.1.9July 23, 2026
- Package metadata now follows the shared compatible
0.1.xdependency range used by this coordinated Tekir release.
v0.1.8June 13, 2026
- The HTTP response cache is now secure by default. Requests carrying
AuthorizationorCookieskip the cache entirely (authenticated: 'bypass'). Setauthenticated: 'vary'to include credential headers in the cache key, or'allow'to opt back into the previous behavior; a customkeybuilder is always honored. Behavior change: authenticated GETs are no longer cached by default. getOrSetnow shares a single in-flight computation across concurrent misses for the same key (single-flight), so a cold key under load runsfactory()once instead of once per request.RedisCacheStore.flush()now deletes only this store's keys viaSCAN+DELover<prefix>*instead ofFLUSHDB, and throws on an empty prefix (which would have wiped the whole database).setuses an atomicSET ... EXwhere the client supports it.- The memory store now enforces a
maxEntriescap (default 10000, FIFO eviction) with periodic sweeping of expired entries, and both stores gained a manualprune(). - Found and fixed with Fable.
v0.1.7May 8, 2026
Cache.get<T>and the per-storeget<T>methods now defaultTtoanyinstead ofunknown. Callers no longer need a redundant generic argument or runtime type guard to read a value back out:await cache.get('user')returns a value you can use directly. Pass an explicit type (cache.get<User>('user')) when you want narrowing back.
v0.1.6April 29, 2026
RedisCacheStorenow accepts any redis-like client without requiring a matchingsend()signature. The interface droppedsendandconnectedfields so@tekir/redis,ioredis, andnode-redisclients all type-check directly without casts.
v0.1.5April 29, 2026
RedisCacheStorenow accepts both@tekir/redis(returnsboolean) and node-redis / ioredis (returnnumber) clients without a TypeScript cast. Existence checks normalise both shapes at the call site.
v0.1.4April 29, 2026
- Memory and database cache setups now type-check cleanly without
@tekir/redisinstalled. The redis store is loaded only when the redis driver is used.
v0.1.3April 29, 2026
- Added
cache()middleware that caches full HTTP responses by URL with TTL, conditional revalidation viaIf-None-Match, andVaryheader support. Skips mutating methods, error responses, andno-storerequests by default. - Added
setDefaultCacheStore()soCacheProviderauto-wires the middleware. Routes can usecache({ ttl: 60 })once the provider is registered, nostoreoption needed.
v0.1.2April 27, 2026
- Split
CacheConfig(loose, whatconfig/cache.tsexports) from a newCacheManagerOptions(strict, what theCacheclass accepts). The provider expands driver configs before instantiating, so directnew Cache({...})callers and config-driven setups both type-check.
v0.1.1April 27, 2026
CacheConfig.storesnow accepts driver-config objects ({ driver: 'memory' }) alongsideCacheStoreinstances, so apps can declare stores inconfig/cache.tswithout importing store classes.
v0.1.0April 1, 2026
- Initial release