Steven Junio
  • Contact

Prisma Accelerate

Prisma Accelerate is a global query caching service that caches data as close as possible to users. It allows for much quicker queries, and reduced database load.


Utilizing Prisma Accelerate is quite a seemless integration with existing prisma libraries. SImply use: import { withAccelerate } from "@prisma/extension-accelerate" 

and initialize your Prisma Client with the extension.

const prisma = new PrismaClient().$extends(withAccelerate());
 
This now gives access to the cacheStrategy property in your queries:
 
const posts = await prisma.post.findMany({
select: {
title: true,
content: true,
id: true,
slug: true,
},

orderBy: {
createdAt: "desc",
},
cacheStrategy: {},
});
 
 
Utilizing this with NextJS can be problematic and must be used with caution. Because Next has built-in caching, these 2 can clash. You must ensure you are only utilizing these in areas where stale data can be shown safely.