Builder's DayOctober 26 · SFGet tickets

Prisma 8 extension

Cache middleware

Serve repeated reads from an in-memory or pluggable cache, opted in per query.

By PrismaPostgreSQLMongoDB

What it does

An opt-in caching middleware built on the intercept hook. Annotate a query with a TTL and identical plans are answered from the cache without touching the driver. Ships an in-memory LRU store and a CacheStore interface for Redis or other backends. Works on PostgreSQL and MongoDB runtimes.

Register it on the client

src/prisma/db.ts
import { createCacheMiddleware } from '@prisma/orm-extension-middleware-cache';
import postgres from '@prisma/orm-postgres/runtime';
import type { Contract } from './contract.d';
import contractJson from './contract.json' with { type: 'json' };

export const db = postgres<Contract>({
  contractJson,
  url: process.env['DATABASE_URL']!,
  middleware: [createCacheMiddleware({ maxEntries: 1_000 })],
});