UNPKG

@graphql-eslint/eslint-plugin

Version:
25 lines (24 loc) 639 B
import debugFactory from "debug"; const log = debugFactory("graphql-eslint:ModuleCache"); class ModuleCache { 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; } } export { ModuleCache };