UNPKG

@graphql-eslint/eslint-plugin

Version:
29 lines (26 loc) 1.01 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug); const log = _debug2.default.call(void 0, "graphql-eslint:ModuleCache"); class ModuleCache {constructor() { ModuleCache.prototype.__init.call(this); } __init() {this.map = /* @__PURE__ */ new Map()} set(cacheKey, result) { if (false) return; this.map.set(cacheKey, { lastSeen: process.hrtime(), result }); log("setting entry for", cacheKey); } get(cacheKey, settings = { lifetime: 10 /* seconds */ }) { if (false) return; const value = this.map.get(cacheKey); if (!value) { log("cache miss for", cacheKey); return; } const { lastSeen, result } = value; if (process.env.NODE || process.hrtime(lastSeen)[0] < settings.lifetime) { return result; } } } exports.ModuleCache = ModuleCache;