fix: improve size calculation for LRU cache and handle nested object content
This commit is contained in:
@@ -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'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user