7
7
8
8
import { DataFetcherError , noCacheFetchOptions } from '@/lib/data' ;
9
9
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' ;
11
12
import { assert } from 'ts-essentials' ;
12
13
import { enrichFilesystem } from './enrich' ;
13
14
import type {
@@ -40,7 +41,7 @@ export async function fetchOpenAPIFilesystem(
40
41
assert ( resolved . openAPIFilesystem ) ;
41
42
return resolved . openAPIFilesystem ;
42
43
}
43
- return fetchFilesystem ( resolved . href ) ;
44
+ return fetchFilesystem ( resolved . href , context . space . id ) ;
44
45
} ) ( ) ;
45
46
46
47
if ( 'error' in filesystem ) {
@@ -54,7 +55,8 @@ export async function fetchOpenAPIFilesystem(
54
55
}
55
56
56
57
const fetchFilesystem = async (
57
- url : string
58
+ url : string ,
59
+ spaceId : string
58
60
) : Promise <
59
61
| Filesystem
60
62
| {
@@ -66,6 +68,7 @@ const fetchFilesystem = async (
66
68
> => {
67
69
'use cache' ;
68
70
try {
71
+ cacheTag ( getCacheTag ( { tag : 'space' , space : spaceId } ) ) ;
69
72
return await fetchFilesystemUncached ( url ) ;
70
73
} catch ( error ) {
71
74
// To avoid hammering the file with requests, we cache the error for around a minute.
@@ -96,6 +99,7 @@ async function fetchFilesystemUncached(
96
99
// https://github.com/cloudflare/workerd/issues/1957
97
100
const response = await fetch ( new URL ( url ) , {
98
101
...noCacheFetchOptions ,
102
+ cache : 'no-store' ,
99
103
signal : options ?. signal ,
100
104
} ) ;
101
105
0 commit comments