From 68287d3df4c35d5033476ed2d0568575c474f4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Thu, 30 Jan 2025 15:16:45 +0100 Subject: [PATCH] Cache API spec for 24 hours, revalidated every 2 hours (#2792) --- .changeset/five-students-rescue.md | 5 +++++ packages/gitbook/src/lib/openapi.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/five-students-rescue.md diff --git a/.changeset/five-students-rescue.md b/.changeset/five-students-rescue.md new file mode 100644 index 000000000..29155e952 --- /dev/null +++ b/.changeset/five-students-rescue.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Cache API spec for 24 hours, revalidated every 2 hours diff --git a/packages/gitbook/src/lib/openapi.ts b/packages/gitbook/src/lib/openapi.ts index 2762f61dd..ba9af9766 100644 --- a/packages/gitbook/src/lib/openapi.ts +++ b/packages/gitbook/src/lib/openapi.ts @@ -7,7 +7,7 @@ import { OpenAPIParseError, } from '@gitbook/react-openapi'; -import { cache, parseCacheResponse, noCacheFetchOptions, CacheFunctionOptions } from '@/lib/cache'; +import { cache, noCacheFetchOptions, CacheFunctionOptions } from '@/lib/cache'; import { parseMarkdown } from './markdown'; import { ResolvedContentRef } from './references'; @@ -68,7 +68,10 @@ const fetcher: OpenAPIFetcher = { const text = await response.text(); const data = await parseOpenAPI({ url, value: text, parseMarkdown }); return { - ...parseCacheResponse(response), + // Cache for 4 hours + ttl: 24 * 60 * 60, + // Revalidate every 2 hours + revalidateBefore: 22 * 60 * 60, data, }; },