From 71b365e5a343b045dba0eaccb6d7c10e7883d391 Mon Sep 17 00:00:00 2001 From: Nicolas Dorseuil Date: Wed, 6 Aug 2025 20:35:47 +0200 Subject: [PATCH] Optimize cache retrieval by bypassing tag cache on hits to improve performance and reduce costs --- packages/gitbook/openNext/incrementalCache.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/gitbook/openNext/incrementalCache.ts b/packages/gitbook/openNext/incrementalCache.ts index 97cce7cafa..9e34dcda22 100644 --- a/packages/gitbook/openNext/incrementalCache.ts +++ b/packages/gitbook/openNext/incrementalCache.ts @@ -48,7 +48,13 @@ class GitbookIncrementalCache implements IncrementalCache { const result = (await localCacheEntry.json()) as WithLastModified< CacheValue >; - return this.returnNullOn404(result); + return this.returnNullOn404({ + ...result, + // Because we use tag cache and also invalidate them every time, + // if we get a cache hit, we don't need to check the tag cache as we already know it's not been revalidated + // this should improve performance even further, and reduce costs + shouldBypassTagCache: true, + }); } const r2Object = await r2.get(cacheKey);