1+ import { invalidateByTag , invalidateByPath , invalidateAll , getCacheStats } from "cache-handlers" ;
2+
3+ export async function POST ( { request } : { request : Request } ) {
4+ try {
5+ const formData = await request . formData ( ) ;
6+ const type = formData . get ( "type" ) as string ;
7+ const value = formData . get ( "value" ) as string ;
8+
9+ let result : { success : boolean ; count ?: number ; error ?: string } ;
10+
11+ switch ( type ) {
12+ case "tag" :
13+ if ( ! value ) {
14+ return Response . json ( { success : false , error : "Tag value is required" } , { status : 400 } ) ;
15+ }
16+ const tagCount = await invalidateByTag ( value ) ;
17+ result = { success : true , count : tagCount } ;
18+ break ;
19+
20+ case "path" :
21+ if ( ! value ) {
22+ return Response . json ( { success : false , error : "Path value is required" } , { status : 400 } ) ;
23+ }
24+ const pathCount = await invalidateByPath ( value ) ;
25+ result = { success : true , count : pathCount } ;
26+ break ;
27+
28+ case "all" :
29+ const allCount = await invalidateAll ( ) ;
30+ result = { success : true , count : allCount } ;
31+ break ;
32+
33+ default :
34+ return Response . json ( { success : false , error : "Invalid invalidation type" } , { status : 400 } ) ;
35+ }
36+
37+ return Response . json ( result ) ;
38+ } catch ( error ) {
39+ console . error ( "Invalidation error:" , error ) ;
40+ return Response . json (
41+ { success : false , error : "Internal server error" } ,
42+ { status : 500 }
43+ ) ;
44+ }
45+ }
46+
47+ export async function GET ( ) {
48+ try {
49+ const stats = await getCacheStats ( ) ;
50+ return Response . json ( {
51+ success : true ,
52+ stats,
53+ } ) ;
54+ } catch ( error ) {
55+ console . error ( "Cache stats error:" , error ) ;
56+ return Response . json (
57+ { success : false , error : "Failed to get cache stats" } ,
58+ { status : 500 }
59+ ) ;
60+ }
61+ }
0 commit comments