@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
25 lines (22 loc) • 951 B
JavaScript
;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) {
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;
if (process.env.NODE || process.hrtime(lastSeen)[0] < settings.lifetime)
return result;
}
}
exports.ModuleCache = ModuleCache;