77
88import { DataFetcherError , noCacheFetchOptions } from '@/lib/data' ;
99import { 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' ;
1112import { assert } from 'ts-essentials' ;
1213import { enrichFilesystem } from './enrich' ;
1314import 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
5657const 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