UNPKG

eyeglass

Version:
54 lines 1.61 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const LRU = require("lru-cache"); function resetGlobalCaches() { realpathSync.resetCache(); existsSync.resetCache(); } exports.resetGlobalCaches = resetGlobalCaches; /* cache real path locations so we don't hit the filesystem more than once for the same path every 5 min. We cap this cache at ~1MB of memory.*/ const realpathCache = new LRU({ max: 1024 * 1024, length: (value, key) => value.length + key.length, maxAge: 5 * 60 * 1000 /* 5 min */, }); function realpathSync(path) { let value = realpathCache.get(path); if (value) { return value; } value = fs.realpathSync(path); realpathCache.set(path, value); return value; } exports.realpathSync = realpathSync; realpathSync.resetCache = () => { realpathCache.reset(); }; let existsCache = Object.create(null); function existsSync(path) { let result = existsCache[path]; if (result === true || result === false) { return result; } else { result = fs.existsSync(path); existsCache[path] = result; return result; } } exports.existsSync = existsSync; existsSync.resetCache = () => { existsCache = Object.create(null); }; //# sourceMappingURL=perf.js.map