refactor: Add caching to the sync endpoint (#819)

* test: caching strategies

* feat: caching

* remove hotfix code

* remove unused import

* fix: adds revalidation to action services

* add environments to product service & type

* fix: fixes caching

* fix: fixes product cache

* add person revalidation to person js endpoints

* update surveys cache rule

* add new caching policy for surveys in sync

---------

Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
This commit is contained in:
Matti Nannt
2023-09-16 15:53:44 +09:00
committed by GitHub
parent 4a3289d394
commit 73ba6feec2
11 changed files with 302 additions and 36 deletions
+10 -7
View File
@@ -1,16 +1,19 @@
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";
function makePrisma() {
const prismaClientSingleton = () => {
return new PrismaClient({
datasources: { db: { url: process.env.DATABASE_URL } },
/* log: ["query", "info"], */
}).$extends(withAccelerate());
}
const globalForPrisma = global as unknown as {
prisma: ReturnType<typeof makePrisma>;
};
export const prisma = globalForPrisma.prisma ?? makePrisma();
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = makePrisma();
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};
export const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;