MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / constructor

Method constructor

lib/cache/on-disk.ts:56–94  ·  view source on GitHub ↗
(cacheName: string, path: string, cacheMb: number)

Source from the content-addressed store, hash-verified

54 private readonly cache: LRUCache<string, CacheEntry>;
55
56 constructor(cacheName: string, path: string, cacheMb: number) {
57 super(cacheName, `OnDiskCache(${path}, ${cacheMb}mb)`, 'disk');
58 this.path = path;
59 this.cacheMb = cacheMb;
60 this.cache = new LRUCache({
61 maxSize: cacheMb * 1024 * 1024,
62 sizeCalculation: n => n.size,
63 noDisposeOnSet: true,
64 dispose: value => fs.unlink(value.path, () => {}),
65 });
66 fs.mkdirSync(path, {recursive: true});
67 const info = getAllFiles(path)
68 .map(({name, fullPath}) => {
69 const stat = fs.statSync(fullPath);
70 if (stat.size === 0 || fullPath.endsWith('.tmp')) {
71 logger.info(`Removing old temporary or broken empty file ${fullPath}`);
72 fs.unlink(fullPath, () => {});
73 return undefined;
74 }
75 return {
76 key: name,
77 sort: stat.ctimeMs,
78 data: {
79 path: fullPath,
80 size: stat.size,
81 },
82 };
83 })
84 .filter(Boolean);
85
86 // Sort oldest first
87
88 // @ts-expect-error filter(Boolean) should have sufficed but doesn't
89 info.sort((x, y) => x.sort - y.sort);
90 for (const i of info) {
91 // @ts-expect-error
92 this.cache.set(i.key, i.data);
93 }
94 }
95
96 override statString(): string {
97 return (

Callers

nothing calls this directly

Calls 3

getAllFilesFunction · 0.85
sortMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected