-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
51 lines (46 loc) · 1.38 KB
/
route.ts
File metadata and controls
51 lines (46 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { NextRequest, NextResponse } from 'next/server';
import { searchCache } from '@/lib/cache';
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const detailed = searchParams.get('detailed') === 'true';
const stats = detailed ? searchCache.getDetailedStats() : searchCache.getStats();
return NextResponse.json({
cache: stats,
timestamp: new Date().toISOString(),
});
} catch (error) {
console.error('Cache stats error:', error);
return NextResponse.json(
{ error: 'Failed to retrieve cache statistics' },
{ status: 500 }
);
}
}
export async function DELETE(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const key = searchParams.get('key');
if (key) {
// Delete specific cache entry
const deleted = searchCache.delete(key);
return NextResponse.json({
deleted,
key,
message: deleted ? 'Cache entry deleted' : 'Cache entry not found'
});
} else {
// Clear entire cache
searchCache.clear();
return NextResponse.json({
message: 'Cache cleared successfully'
});
}
} catch (error) {
console.error('Cache management error:', error);
return NextResponse.json(
{ error: 'Failed to manage cache' },
{ status: 500 }
);
}
}