Cache

Speed up your application with a consistent caching API. Supports Redis, Valkey, and in-memory stores with automatic serialization and TTL management.

rediskey-valueperformancettl

Providers

Redis

In-memory data store with persistence, pub/sub, and rich data structures

ioredis
REDIS_URL

Valkey

Open-source Redis-compatible in-memory data store

ioredis
VALKEY_URL

In-Memory

Process-local cache for development and single-instance deployments

Usage

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
)

Get Started

Add cache to your Primstack project with a single command:

prim cache init