fix: implement cache control logic in Google Sheets API route

This commit is contained in:
Lucas Rayan committed 2025-11-09 18:19:01 -03:00
1 parent fe06241517
commit b89dd3e880
1 file changed
+12 -5
+12 -5
View File
@@ -1,8 +1,11 @@
import { google } from 'googleapis'; import { google } from 'googleapis';
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
// Configurar cache de 1 hora // Habilitar/desabilitar cache
export const revalidate = 3600; const ENABLE_CACHE = false;
// Configurar cache de 1 hora (se habilitado)
export const revalidate = ENABLE_CACHE ? 3600 : 0;
export async function GET() { export async function GET() {
try { try {
@@ -32,10 +35,14 @@ export async function GET() {
return obj; return obj;
}); });
const responseHeaders = ENABLE_CACHE ? {
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=7200'
} : {
'Cache-Control': 'no-store, no-cache, must-revalidate'
};
return NextResponse.json({ data, headers }, { return NextResponse.json({ data, headers }, {
headers: { headers: responseHeaders
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=7200'
}
}); });
} catch (error) { } catch (error) {
console.error('Erro ao buscar dados do Google Sheets:', error); console.error('Erro ao buscar dados do Google Sheets:', error);