Files
NapCatQQ/.pnpm-store/v3/files/43/53faecf675abb9a3f8e6cc9af342db4939e231284273676efcfe72897314bfea94ce627c137522ee2ed70554aceb94646ba4be0d668ec0bff3f262e688a3d8
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

38 lines
1.1 KiB
Plaintext

import debug from 'debug';
const log = debug('eslint-plugin-import-x:utils:ModuleCache');
export class ModuleCache {
constructor(map = new Map()) {
this.map = map;
}
set(cacheKey, result) {
this.map.set(cacheKey, {
result,
lastSeen: process.hrtime(),
});
log('setting entry for', cacheKey);
return result;
}
get(cacheKey, settings) {
const cache = this.map.get(cacheKey);
if (cache) {
if (process.hrtime(cache.lastSeen)[0] < settings.lifetime) {
return cache.result;
}
}
else {
log('cache miss for', cacheKey);
}
}
static getSettings(settings) {
const cacheSettings = {
lifetime: 30,
...settings['import-x/cache'],
};
if (typeof cacheSettings.lifetime === 'string' &&
['∞', 'Infinity'].includes(cacheSettings.lifetime)) {
cacheSettings.lifetime = Number.POSITIVE_INFINITY;
}
return cacheSettings;
}
}
//# sourceMappingURL=module-cache.js.map