Speed up your application with a consistent caching API. Supports Redis, Valkey, and in-memory stores with automatic serialization and TTL management.
In-memory data store with persistence, pub/sub, and rich data structures
REDIS_URLOpen-source Redis-compatible in-memory data store
VALKEY_URLProcess-local cache for development and single-instance deployments
Cache a query result
Store and retrieve data with automatic TTL
import { cache } from '@/lib/cache'
const user = await cache.getOrSet(
`user:${userId}`,
() => db.query.users.findFirst({ where: eq(users.id, userId) }),
{ ttl: 300 } // 5 minutes
)Add cache to your Primstack project with a single command:
prim cache init