fix: improve size calculation for LRU cache and handle nested object content

This commit is contained in:
xutianyi
2026-04-05 01:43:18 +08:00
parent f49c7d7e8c
commit 354c11f035
2 changed files with 27 additions and 4 deletions
+12 -1
View File
@@ -34,7 +34,18 @@ export class FileStateCache {
this.cache = new LRUCache<string, FileState>({
max: maxEntries,
maxSize: maxSizeBytes,
sizeCalculation: value => Math.max(1, Buffer.byteLength(value.content)),
sizeCalculation: value => {
const c = value.content
const s =
typeof c === 'string'
? c
: c === null || c === undefined
? ''
: typeof c === 'object'
? JSON.stringify(c)
: String(c)
return Math.max(1, Buffer.byteLength(s, 'utf8'))
},
})
}