@theoven/cache
v0.6.1
Published
Caching for Oven — memory and Redis, with tag invalidation and stampede protection
Maintainers
Readme
@theoven/cache
Caching for Oven — memory and Redis, with tag invalidation and stampede protection.
Install
bun add @theoven/cacheUsage
import { cache, redisCache } from '@theoven/cache'
const app = createApp().use(cache(redisCache({ url: env.string('REDIS_URL') })))
const user = await ctx.cache.cached(
`user:${id}`,
() => ctx.db.select().from(users).where(eq(users.id, id)),
{ ttl: 60_000, tags: [`user:${id}`] },
)
await ctx.cache.invalidate(`user:${id}`) // clears everything tagged with itConcurrent misses for the same key share one call to the producer. Without that, a popular key expiring means every in-flight request recomputes it at once — the cache stampede, and the reason a cache can make an outage worse rather than better.
The in-process driver is refused in production: per-instance caches disagree, so a user sees one value, refreshes, and sees another — a bug that only reproduces under load.
Documentation
https://theoven.app/docs/bricks/cache/
License
MIT
