@@ -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'
1414import path from '../../../shared/lib/isomorphic/path'
1515import {
1616 NEXT_CACHE_TAGS_HEADER ,
@@ -23,6 +23,7 @@ import {
2323} from '../../../lib/constants'
2424import { isStale , tagsManifest } from './tags-manifest.external'
2525import { MultiFileWriter } from '../../../lib/multi-file-writer'
26+ import { getMemoryCache } from './memory-cache.external'
2627
2728type 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 }
0 commit comments