Skip to content
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
3 changes: 3 additions & 0 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
| 'http'
| 'https',
})
incrementalCache.resetRequestCache()
addRequestMeta(req, 'incrementalCache', incrementalCache)
;(globalThis as any).__incrementalCache = incrementalCache
}
Expand Down Expand Up @@ -2141,6 +2142,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
| 'https',
}))

incrementalCache?.resetRequestCache()

const { routeModule } = components

type Renderer = (context: {
Expand Down
13 changes: 7 additions & 6 deletions packages/next/src/server/lib/incremental-cache/fetch-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export default class FetchCache implements CacheHandler {
}
}

public resetRequestCache(): void {
memoryCache?.reset()
}

public async revalidateTag(tag: string) {
if (this.debug) {
console.log('revalidateTag', tag)
Expand Down Expand Up @@ -157,14 +161,11 @@ export default class FetchCache implements CacheHandler {
return null
}

// memory cache is cleared at the end of each request
// so that revalidate events are pulled from upstream
// on successive requests
let data = memoryCache?.get(key)

// memory cache data is only leveraged for up to 2 seconds
// so that revalidation events can be pulled from source
if (Date.now() - (data?.lastModified || 0) > 2000) {
data = undefined
}

// get data from fetch cache
if (!data && this.cacheEndpoint) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default class FileSystemCache implements CacheHandler {
}
}

public resetRequestCache(): void {}

private loadTagsManifest() {
if (!this.tagsManifestPath || !this.fs || tagsManifest) return
try {
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/server/lib/incremental-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class CacheHandler {
): Promise<void> {}

public async revalidateTag(_tag: string): Promise<void> {}

public resetRequestCache(): void {}
}

export class IncrementalCache implements IncrementalCacheType {
Expand Down Expand Up @@ -213,6 +215,10 @@ export class IncrementalCache implements IncrementalCacheType {
return fetchCache ? pathname : normalizePagePath(pathname)
}

resetRequestCache() {
this.cacheHandler?.resetRequestCache?.()
}

async unlock(cacheKey: string) {
const unlock = this.unlocks.get(cacheKey)
if (unlock) {
Expand Down