Skip to content

Prisma Adapter makes a lot of SQL queries to the database. Is it possible to cache it? #11134

Answered by shivdeepak
shivdeepak asked this question in Help
Discussion options

You must be logged in to vote

I have a solution in mind. I have defined a NodeCacheAdapater, and I wrapped PrismaAdapter with it. It works well for the repeated calls to getSessionAndUser, and I am planning to run this in production.

@balazsorban44 @ndom91 is this something the project can make use of? I will create a PR.

Sample Usage (src/auth.ts):

import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client/edge"
import NodeCacheAdapter from "./node-cache-adapter"

const prisma = new PrismaClient();

export const { handlers, signIn, signOut, auth } = NextAuth({
  adapter: NodeCacheAdapter(PrismaAdapter(prisma), { ttl: 60 }),
  providers: [
    ...
  

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@shivdeepak
Comment options

@ndom91
Comment options

@shivdeepak
Comment options

Answer selected by shivdeepak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants