@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
32 lines (31 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModuleCache = void 0;
const tslib_1 = require("tslib");
// Based on the `eslint-plugin-import`'s cache
// https://github.com/import-js/eslint-plugin-import/blob/main/utils/ModuleCache.js
const debug_1 = tslib_1.__importDefault(require("debug"));
const log = (0, debug_1.default)('graphql-eslint:ModuleCache');
class ModuleCache {
constructor() {
this.map = new Map();
}
set(cacheKey, result) {
this.map.set(cacheKey, { lastSeen: process.hrtime(), result });
log('setting entry for', cacheKey);
}
get(cacheKey, settings = { lifetime: 10 /* seconds */ }) {
const value = this.map.get(cacheKey);
if (!value) {
log('cache miss for', cacheKey);
return;
}
const { lastSeen, result } = value;
// check freshness
if (process.env.NODE /* don't check for ESLint CLI */ ||
process.hrtime(lastSeen)[0] < settings.lifetime) {
return result;
}
}
}
exports.ModuleCache = ModuleCache;