Scale database access
Production applications that need managed connection pooling and global caching.
Prisma · Function
withAccelerate() is the Prisma Client extension entry point for Prisma Accelerate. Apply it with $extends() to enable Accelerate integration and query-level cache controls.
withAccelerate() is a Prisma Client extension from @prisma/extension-accelerate. Pass its result to $extends() so the client can use Accelerate features, including per-query cache controls such as ttl and swr.
withAccelerate()A Prisma Client extension that is applied with $extends().
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";
const prisma = new PrismaClient().$extends(withAccelerate());
const users = await prisma.user.findMany({
cacheStrategy: { ttl: 30, swr: 60 },
});
console.log(users);Extends Prisma Client with Accelerate, then applies a time-to-live and stale-while-revalidate policy to a query.
Production applications that need managed connection pooling and global caching.
Queries that need explicit freshness and stale-while-revalidate behavior.
Development setups that use a local database while keeping the Accelerate extension in client code.
withAccelerate() returns the Accelerate Prisma Client extension, and $extends() applies it to a PrismaClient instance. This enables Accelerate integration and its query-level cache controls.
Follow-up: What controls cache behavior for a query? Use cacheStrategy with ttl for freshness and swr for serving stale results while refreshed data is fetched.
Import it from @prisma/extension-accelerate and pass its result to $extends() on PrismaClient. The resulting client can use Accelerate features.
Follow-up: How would you use it with a local database? Keep the extension in development, but do not expect Accelerate's connection pooling or caching to operate.
A query can specify cacheStrategy with ttl and swr values. ttl defines how long data is considered fresh, while swr permits stale data to be served during revalidation.
Follow-up: What infrastructure does Accelerate provide in production? It provides connection pooling and a global database cache for production traffic.
PrismaClient$extends@prisma/extension-acceleratecacheStrategyttlswr