| 28 | * or mixed path separators on Windows (/ vs \). |
| 29 | */ |
| 30 | export class FileStateCache { |
| 31 | private cache: LRUCache<string, FileState> |
| 32 | |
| 33 | constructor(maxEntries: number, maxSizeBytes: number) { |
| 34 | this.cache = new LRUCache<string, FileState>({ |
| 35 | max: maxEntries, |
| 36 | maxSize: maxSizeBytes, |
| 37 | sizeCalculation: value => Math.max(1, Buffer.byteLength(value.content)), |
| 38 | }) |
| 39 | } |
| 40 | |
| 41 | get(key: string): FileState | undefined { |
| 42 | return this.cache.get(normalize(key)) |
| 43 | } |
| 44 | |
| 45 | set(key: string, value: FileState): this { |
| 46 | this.cache.set(normalize(key), value) |
| 47 | return this |
| 48 | } |
| 49 | |
| 50 | has(key: string): boolean { |
| 51 | return this.cache.has(normalize(key)) |
| 52 | } |
| 53 | |
| 54 | delete(key: string): boolean { |
| 55 | return this.cache.delete(normalize(key)) |
| 56 | } |
| 57 | |
| 58 | clear(): void { |
| 59 | this.cache.clear() |
| 60 | } |
| 61 | |
| 62 | get size(): number { |
| 63 | return this.cache.size |
| 64 | } |
| 65 | |
| 66 | get max(): number { |
| 67 | return this.cache.max |
| 68 | } |
| 69 | |
| 70 | get maxSize(): number { |
| 71 | return this.cache.maxSize |
| 72 | } |
| 73 | |
| 74 | get calculatedSize(): number { |
| 75 | return this.cache.calculatedSize |
| 76 | } |
| 77 | |
| 78 | keys(): Generator<string> { |
| 79 | return this.cache.keys() |
| 80 | } |
| 81 | |
| 82 | entries(): Generator<[string, FileState]> { |
| 83 | return this.cache.entries() |
| 84 | } |
| 85 | |
| 86 | dump(): ReturnType<LRUCache<string, FileState>['dump']> { |
| 87 | return this.cache.dump() |
nothing calls this directly
no outgoing calls
no test coverage detected