Skip to content

Commit 54ec1b2

Browse files
committed
fix: added entrypoint
1 parent 231cc50 commit 54ec1b2

3 files changed

Lines changed: 37 additions & 43 deletions

File tree

packages/next/src/server/lib/incremental-cache/file-system-cache.external.ts renamed to packages/next/src/server/lib/incremental-cache/file-system-cache.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type SetIncrementalResponseCacheContext,
1111
} from '../../response-cache'
1212

13-
import { LRUCache } from '../lru-cache'
13+
import type { LRUCache } from '../lru-cache'
1414
import path from '../../../shared/lib/isomorphic/path'
1515
import {
1616
NEXT_CACHE_TAGS_HEADER,
@@ -23,6 +23,7 @@ import {
2323
} from '../../../lib/constants'
2424
import { isStale, tagsManifest } from './tags-manifest.external'
2525
import { MultiFileWriter } from '../../../lib/multi-file-writer'
26+
import { getMemoryCache } from './memory-cache.external'
2627

2728
type FileSystemCacheContext = Omit<
2829
CacheHandlerContext,
@@ -52,31 +53,7 @@ export default class FileSystemCache implements CacheHandler {
5253
console.log('using memory store for fetch cache')
5354
}
5455

55-
FileSystemCache.memoryCache = new LRUCache(
56-
ctx.maxMemoryCacheSize,
57-
function length({ value }) {
58-
if (!value) {
59-
return 25
60-
} else if (value.kind === CachedRouteKind.REDIRECT) {
61-
return JSON.stringify(value.props).length
62-
} else if (value.kind === CachedRouteKind.IMAGE) {
63-
throw new Error('invariant image should not be incremental-cache')
64-
} else if (value.kind === CachedRouteKind.FETCH) {
65-
return JSON.stringify(value.data || '').length
66-
} else if (value.kind === CachedRouteKind.APP_ROUTE) {
67-
return value.body.length
68-
}
69-
// rough estimate of size of cache value
70-
return (
71-
value.html.length +
72-
(JSON.stringify(
73-
value.kind === CachedRouteKind.APP_PAGE
74-
? value.rscData
75-
: value.pageData
76-
)?.length || 0)
77-
)
78-
}
79-
)
56+
FileSystemCache.memoryCache = getMemoryCache(ctx.maxMemoryCacheSize)
8057
} else if (FileSystemCache.debug) {
8158
console.log('memory store already initialized')
8259
}

packages/next/src/server/lib/incremental-cache/index.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -452,23 +452,6 @@ export class IncrementalCache implements IncrementalCacheType {
452452
return null
453453
}
454454

455-
// As we're able to get the cache entry for this fetch, and the prerender
456-
// resume data cache (RDC) is available, it must have been populated by a
457-
// previous fetch, but was not yet present in the in-memory cache. This
458-
// could be the case when performing multiple renders in parallel during
459-
// build time where we de-duplicate the fetch calls.
460-
//
461-
// We add it to the RDC so that the next fetch call will be able to use it
462-
// and it won't have to reach into the fetch cache implementation.
463-
const workUnitStore = workUnitAsyncStorage.getStore()
464-
if (workUnitStore) {
465-
const prerenderResumeDataCache =
466-
getPrerenderResumeDataCache(workUnitStore)
467-
if (prerenderResumeDataCache) {
468-
prerenderResumeDataCache.fetch.set(cacheKey, cacheData.value)
469-
}
470-
}
471-
472455
const revalidate = ctx.revalidate || cacheData.value.revalidate
473456
const age =
474457
(performance.timeOrigin +
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { CacheHandlerValue } from '.'
2+
import { CachedRouteKind } from '../../response-cache/types'
3+
import { LRUCache } from '../lru-cache'
4+
5+
let memoryCache: LRUCache<CacheHandlerValue> | undefined
6+
7+
export function getMemoryCache(maxMemoryCacheSize: number) {
8+
if (!memoryCache) {
9+
memoryCache = new LRUCache(maxMemoryCacheSize, function length({ value }) {
10+
if (!value) {
11+
return 25
12+
} else if (value.kind === CachedRouteKind.REDIRECT) {
13+
return JSON.stringify(value.props).length
14+
} else if (value.kind === CachedRouteKind.IMAGE) {
15+
throw new Error('invariant image should not be incremental-cache')
16+
} else if (value.kind === CachedRouteKind.FETCH) {
17+
return JSON.stringify(value.data || '').length
18+
} else if (value.kind === CachedRouteKind.APP_ROUTE) {
19+
return value.body.length
20+
}
21+
// rough estimate of size of cache value
22+
return (
23+
value.html.length +
24+
(JSON.stringify(
25+
value.kind === CachedRouteKind.APP_PAGE
26+
? value.rscData
27+
: value.pageData
28+
)?.length || 0)
29+
)
30+
})
31+
}
32+
33+
return memoryCache
34+
}

0 commit comments

Comments
 (0)