Add cache tags

This commit is contained in:
MartinBraquet
2025-07-30 14:44:57 +02:00
parent de9269e2e9
commit 4fb5aca76b
4 changed files with 20 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ import { NextResponse } from "next/server";
export async function GET() {
try {
// Get all interests from the database
const cacheStrategy = { swr: 60, ttl: 60 };
const cacheStrategy = { swr: 60, ttl: 60, tags: ["interests"] };
const interests = await prisma.interest.findMany({
select: {
id: true,

View File

@@ -9,6 +9,7 @@ export async function GET(
const params = await context.params;
const { id } = params;
const cacheStrategy = { swr: 3600, ttl: 3600, tags: ["profiles/[id]"] };
const user = await prisma.user.findUnique({
where: { id },
select: {
@@ -26,6 +27,7 @@ export async function GET(
},
},
},
cacheStrategy: cacheStrategy,
});
// If user not found, return 404

View File

@@ -84,7 +84,7 @@ export async function GET(request: Request) {
}
// Fetch paginated and filtered profiles
const cacheStrategy = { swr: 3600, ttl: 3600 };
const cacheStrategy = { swr: 3600, ttl: 3600 , tags: ["profiles"]};
const profiles = await prisma.user.findMany({
skip: offset,
take: profilesPerPage,

View File

@@ -1,7 +1,11 @@
import {prisma} from "@/lib/server/prisma";
import {PrismaClient} from "@prisma/client";
// Cannot import from prisma.ts as we are outside the server
const prisma = new PrismaClient({log: ['query']})
async function main() {
// Create some interests and cause areas
await prisma.interest.createMany({
data: [
@@ -31,17 +35,25 @@ async function main() {
skipDuplicates: true,
});
const names = [
'Alice Wonderland',
'Bob the Builder',
'Emily McConaughey',
'Alex Hepburn',
'Laurent Golden'
]
// Get actual Interest & CauseArea objects
const allInterests = await prisma.interest.findMany();
const allCauseAreas = await prisma.causeArea.findMany();
const allConnections = await prisma.connection.findMany();
// Create mock users
for (let i = 1; i <= 5; i++) {
for (let i = 0; i < 5; i++) {
const user = await prisma.user.create({
data: {
email: `user${i}@bayesbond.com`,
name: `User ${i}`,
email: `user${i+1}@bayesbond.com`,
name: names[i],
image: null,
profile: {
create: {