From 9771083b2be8053ebbe72be81ba451b9ab2d7b3f Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Tue, 14 Nov 2023 16:31:39 -0800 Subject: [PATCH] fix incorrect fetch cache handling --- .../lib/incremental-cache/fetch-cache.ts | 36 +++++-------------- .../incremental-cache/file-system-cache.ts | 29 ++++----------- 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/packages/next/src/server/lib/incremental-cache/fetch-cache.ts b/packages/next/src/server/lib/incremental-cache/fetch-cache.ts index 896795ec08737..e0361c5c23075 100644 --- a/packages/next/src/server/lib/incremental-cache/fetch-cache.ts +++ b/packages/next/src/server/lib/incremental-cache/fetch-cache.ts @@ -142,19 +142,13 @@ export default class FetchCache implements CacheHandler { } } - public async get( - key: string, - ctx: { - tags?: string[] - softTags?: string[] - fetchCache?: boolean - fetchUrl?: string - fetchIdx?: number - } - ) { - const { tags, softTags, fetchCache, fetchIdx, fetchUrl } = ctx + public async get(...args: Parameters) { + const [key, ctx = {}] = args + const { tags, softTags, kindHint, fetchIdx, fetchUrl } = ctx - if (!fetchCache) return null + if (kindHint !== 'fetch') { + return null + } if (Date.now() < rateLimitedUntil) { if (this.debug) { @@ -262,21 +256,9 @@ export default class FetchCache implements CacheHandler { return data || null } - public async set( - key: string, - data: CacheHandlerValue['value'], - { - fetchCache, - fetchIdx, - fetchUrl, - tags, - }: { - tags?: string[] - fetchCache?: boolean - fetchUrl?: string - fetchIdx?: number - } - ) { + public async set(...args: Parameters) { + const [key, data, ctx] = args + const { fetchCache, fetchIdx, fetchUrl, tags } = ctx if (!fetchCache) return if (Date.now() < rateLimitedUntil) { diff --git a/packages/next/src/server/lib/incremental-cache/file-system-cache.ts b/packages/next/src/server/lib/incremental-cache/file-system-cache.ts index 33ab3d3a01d65..570c867eae832 100644 --- a/packages/next/src/server/lib/incremental-cache/file-system-cache.ts +++ b/packages/next/src/server/lib/incremental-cache/file-system-cache.ts @@ -1,10 +1,7 @@ import type { RouteMetadata } from '../../../export/routes/types' import type { CacheHandler, CacheHandlerContext, CacheHandlerValue } from './' import type { CacheFs } from '../../../shared/lib/utils' -import type { - CachedFetchValue, - IncrementalCacheKindHint, -} from '../../response-cache' +import type { CachedFetchValue } from '../../response-cache' import LRUCache from 'next/dist/compiled/lru-cache' import path from '../../../shared/lib/isomorphic/path' @@ -118,18 +115,9 @@ export default class FileSystemCache implements CacheHandler { } } - public async get( - key: string, - { - tags, - softTags, - kindHint, - }: { - tags?: string[] - softTags?: string[] - kindHint?: IncrementalCacheKindHint - } = {} - ) { + public async get(...args: Parameters) { + const [key, ctx = {}] = args + const { tags, softTags, kindHint } = ctx let data = memoryCache?.get(key) // let's check the disk for seed data @@ -297,13 +285,8 @@ export default class FileSystemCache implements CacheHandler { return data ?? null } - public async set( - key: string, - data: CacheHandlerValue['value'], - ctx: { - tags?: string[] - } - ) { + public async set(...args: Parameters) { + const [key, data, ctx] = args memoryCache?.set(key, { value: data, lastModified: Date.now(),