From 1abc54f3304c3eab8e6718026b3b444a518be3d3 Mon Sep 17 00:00:00 2001 From: Noah Gundotra Date: Wed, 20 Nov 2024 16:16:20 -0500 Subject: [PATCH] Cache ping data (#417) Cache ping data with NextJS data cache --- app/api/ping/[network]/route.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/api/ping/[network]/route.ts b/app/api/ping/[network]/route.ts index 97d2ecfe..cc16d2d5 100644 --- a/app/api/ping/[network]/route.ts +++ b/app/api/ping/[network]/route.ts @@ -1,4 +1,3 @@ -import { fetch } from 'cross-fetch'; import { NextResponse } from 'next/server'; type Params = { @@ -25,11 +24,12 @@ export async function GET(_request: Request, { params: { network } }: Params) { const responses = await Promise.all( PING_INTERVALS.map(interval => fetch(`https://www.validators.app/api/v1/ping-thing-stats/${network}.json?interval=${interval}`, { - cache: 'no-store', headers: { - 'Cache-Control': 'no-store, max-age=0', Token: process.env.PING_API_KEY || '', }, + next: { + revalidate: 60, + }, }) ) ); @@ -43,7 +43,7 @@ export async function GET(_request: Request, { params: { network } }: Params) { return NextResponse.json(data, { headers: { - 'Cache-Control': 'public, max-age=30', + 'Cache-Control': 'no-store, max-age=0', }, }); }