Skip to content

Commit 955cebf

Browse files
conico974Nicolas Dorseuil
andauthored
Add cache tags for fetchFileSystem (#3489)
Co-authored-by: Nicolas Dorseuil <[email protected]>
1 parent 7c951ef commit 955cebf

File tree

1 file changed

+7
-3
lines changed
  • packages/gitbook/src/lib/openapi

1 file changed

+7
-3
lines changed

packages/gitbook/src/lib/openapi/fetch.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77

88
import { DataFetcherError, noCacheFetchOptions } from '@/lib/data';
99
import { resolveContentRef } from '@/lib/references';
10-
import { unstable_cacheLife as cacheLife } from 'next/cache';
10+
import { getCacheTag } from '@gitbook/cache-tags';
11+
import { unstable_cacheLife as cacheLife, unstable_cacheTag as cacheTag } from 'next/cache';
1112
import { assert } from 'ts-essentials';
1213
import { enrichFilesystem } from './enrich';
1314
import type {
@@ -40,7 +41,7 @@ export async function fetchOpenAPIFilesystem(
4041
assert(resolved.openAPIFilesystem);
4142
return resolved.openAPIFilesystem;
4243
}
43-
return fetchFilesystem(resolved.href);
44+
return fetchFilesystem(resolved.href, context.space.id);
4445
})();
4546

4647
if ('error' in filesystem) {
@@ -54,7 +55,8 @@ export async function fetchOpenAPIFilesystem(
5455
}
5556

5657
const fetchFilesystem = async (
57-
url: string
58+
url: string,
59+
spaceId: string
5860
): Promise<
5961
| Filesystem
6062
| {
@@ -66,6 +68,7 @@ const fetchFilesystem = async (
6668
> => {
6769
'use cache';
6870
try {
71+
cacheTag(getCacheTag({ tag: 'space', space: spaceId }));
6972
return await fetchFilesystemUncached(url);
7073
} catch (error) {
7174
// To avoid hammering the file with requests, we cache the error for around a minute.
@@ -96,6 +99,7 @@ async function fetchFilesystemUncached(
9699
// https://github.com/cloudflare/workerd/issues/1957
97100
const response = await fetch(new URL(url), {
98101
...noCacheFetchOptions,
102+
cache: 'no-store',
99103
signal: options?.signal,
100104
});
101105

0 commit comments

Comments
 (0)