@trieb.work/nextjs-turbo-redis-cache
Version:
Designed for speed, scalability, and optimized performance, nextjs-turbo-redis-cache is your custom cache handler for demanding production environments.
25 lines (18 loc) • 493 B
text/typescript
import { NextResponse } from 'next/server';
import { cacheLife, cacheTag } from 'next/cache';
let counter = 0;
export async function GET() {
const data = await getCachedDataWithLife();
return NextResponse.json(data);
}
async function getCachedDataWithLife() {
'use cache';
cacheLife({ stale: 1, revalidate: 2, expire: 5 });
cacheTag('cache-life-test');
counter++;
return {
counter,
timestamp: Date.now(),
profile: { stale: 1, revalidate: 2, expire: 5 },
};
}