Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Function

withAccelerate

withAccelerate() is the Prisma Client extension entry point for Prisma Accelerate. Apply it with $extends() to enable Accelerate integration and query-level cache controls.

How it works

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.

Syntax

withAccelerate()

Returns

A Prisma Client extension that is applied with $extends().

Key points

  • The extension connects Prisma Client to Accelerate features intended for production traffic: connection pooling and global caching.
  • After extension, individual queries can configure caching with cacheStrategy values such as ttl and swr.
  • Install and import the dedicated client extension package to integrate Accelerate with Prisma ORM.
  • The documented setup creates PrismaClient and applies withAccelerate() through $extends().
  • The local-development setup supports the extension without providing the hosted pooling and caching capabilities.

Common mistakes

  • A local database can be used with the extension during development, but Accelerate's pooling and caching features are unavailable.
  • Using an Accelerate connection string changes query routing; ensure DATABASE_URL is appropriate for the environment.

Example: Enable Accelerate and query with caching

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.

When to use it

Scale database access

Production applications that need managed connection pooling and global caching.

Control query caching

Queries that need explicit freshness and stale-while-revalidate behavior.

Align development and production client setup

Development setups that use a local database while keeping the Accelerate extension in client code.

Interview questions

QWhat does withAccelerate() do?

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.

QHow is withAccelerate() added to Prisma Client?

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.

QHow do ttl and swr relate to withAccelerate()?

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-accelerate
  • cacheStrategy
  • ttl
  • swr

Source: Local development for Prisma Accelerate. Checked 2026-10-16.