fix: implement cache control logic in Google Sheets API route
This commit is contained in:
1 parent
fe06241517
commit
b89dd3e880
1 file changed
+12
-5
+12
-5
@@ -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;
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({ data, headers }, {
|
const responseHeaders = ENABLE_CACHE ? {
|
||||||
headers: {
|
|
||||||
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=7200'
|
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate=7200'
|
||||||
}
|
} : {
|
||||||
|
'Cache-Control': 'no-store, no-cache, must-revalidate'
|
||||||
|
};
|
||||||
|
|
||||||
|
return NextResponse.json({ data, headers }, {
|
||||||
|
headers: responseHeaders
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erro ao buscar dados do Google Sheets:', error);
|
console.error('Erro ao buscar dados do Google Sheets:', error);
|
||||||
|
|||||||
Reference in new issue
Block a user