File tree Expand file tree Collapse file tree 5 files changed +17
-0
lines changed
Expand file tree Collapse file tree 5 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { z } from "zod";
33import { NameIdSchema , updateContestSchema } from "@/lib/validations" ;
44import { getOrgIdFromNameId } from "@/app/api/service" ;
55import { deleteContest , getContestByNameId , updateContest } from "../service" ;
6+ import { invalidateCacheKey } from "@/lib/cache/utils" ;
67
78export async function GET (
89 _request : NextRequest ,
@@ -47,6 +48,7 @@ export async function PATCH(
4748 NameIdSchema . parse ( params . contestId ) ,
4849 data ,
4950 ) ;
51+ await invalidateCacheKey ( `contest:${ orgId } :${ params . contestId } ` ) ;
5052 return NextResponse . json ( contest ) ;
5153 } catch ( error ) {
5254 if ( error instanceof z . ZodError ) {
@@ -77,6 +79,7 @@ export async function DELETE(
7779 orgId ,
7880 NameIdSchema . parse ( params . contestId ) ,
7981 ) ;
82+ await invalidateCacheKey ( `contest:${ orgId } :${ params . contestId } ` ) ;
8083 return NextResponse . json ( contest ) ;
8184 } catch ( error ) {
8285 if ( error instanceof z . ZodError ) {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { z } from "zod";
33import { NameIdSchema , updateProblemSchema } from "@/lib/validations" ;
44import { getOrgIdFromNameId } from "@/app/api/service" ;
55import * as problemService from "./service" ;
6+ import { invalidateCacheKey } from "@/lib/cache/utils" ;
67
78export async function GET (
89 _req : NextRequest ,
@@ -47,6 +48,7 @@ export async function PATCH(
4748 problemCode ,
4849 data ,
4950 ) ;
51+ await invalidateCacheKey ( `org:problem:${ orgId } :${ params . problemId } ` ) ;
5052 return NextResponse . json ( problem ) ;
5153 } catch ( error ) {
5254 if ( error instanceof z . ZodError ) {
@@ -76,6 +78,7 @@ export async function DELETE(
7678 const problemCode = NameIdSchema . parse ( params . problemId ) ;
7779
7880 await problemService . deleteProblem ( orgId , problemCode ) ;
81+ await invalidateCacheKey ( `org:problem:${ orgId } :${ params . problemId } ` ) ;
7982 return new Response ( null , { status : 204 } ) ;
8083 } catch ( error ) {
8184 if ( error instanceof z . ZodError ) {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { NextRequest, NextResponse } from "next/server";
55import { NameIdSchema } from "@/app/api/types" ;
66import { problemSchema } from "@/lib/validations" ;
77import { z } from "zod" ;
8+ import { invalidateCacheKey } from "@/lib/cache/utils" ;
89
910export async function GET (
1011 _req : NextRequest ,
@@ -52,6 +53,8 @@ export async function POST(
5253 validatedTestCases ,
5354 ) ;
5455
56+ await invalidateCacheKey ( `org:problems:${ orgId } ` ) ;
57+
5558 return NextResponse . json ( problem , { status : 201 } ) ;
5659 } catch ( error ) {
5760 if ( error instanceof z . ZodError ) {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { eq } from "drizzle-orm";
55import { z } from "zod" ;
66import { getOrgIdFromNameId } from "../../service" ;
77import { getOrgByOrgId } from "./service" ;
8+ import { invalidateCacheKey } from "@/lib/cache/utils" ;
89
910const updateOrgSchema = z . object ( {
1011 name : z . string ( ) . optional ( ) ,
@@ -54,6 +55,8 @@ export async function PATCH(
5455 . where ( eq ( orgs . id , orgId ) )
5556 . returning ( ) ;
5657
58+ await invalidateCacheKey ( `org:${ orgId } ` ) ;
59+
5760 return updatedOrg
5861 ? NextResponse . json ( updatedOrg )
5962 : NextResponse . json ( { message : "Organization not found" } , { status : 404 } ) ;
Original file line number Diff line number Diff line change @@ -43,3 +43,8 @@ export async function withDataCache<T>(
4343 throw error ;
4444 }
4545}
46+
47+ export async function invalidateCacheKey ( key : string ) : Promise < number > {
48+ const redis = getRedis ( ) ;
49+ return redis . del ( key ) ;
50+ }
You can’t perform that action at this time.
0 commit comments