Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect fetch cache handling #58460

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 9 additions & 27 deletions packages/next/src/server/lib/incremental-cache/fetch-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CacheHandler['get']>) {
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) {
Expand Down Expand Up @@ -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<CacheHandler['set']>) {
const [key, data, ctx] = args
const { fetchCache, fetchIdx, fetchUrl, tags } = ctx
if (!fetchCache) return

if (Date.now() < rateLimitedUntil) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -120,18 +117,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<CacheHandler['get']>) {
const [key, ctx = {}] = args
const { tags, softTags, kindHint } = ctx
let data = memoryCache?.get(key)

// let's check the disk for seed data
Expand Down Expand Up @@ -302,13 +290,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<CacheHandler['set']>) {
const [key, data, ctx] = args
memoryCache?.set(key, {
value: data,
lastModified: Date.now(),
Expand Down
Loading