UNPKG

greybel-languageserver-core

Version:
39 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentMergerCache = void 0; const lru_cache_1 = require("lru-cache"); const hash_1 = require("../hash"); class DocumentMergerCache { constructor() { this.typeDocuments = new lru_cache_1.LRUCache({ max: 100, ttl: 1000 * 60 * 5 // 5 minutes }); this.keyToDocumentUriMap = new Map(); } createCacheKey(source, documents) { let result = (0, hash_1.hash)(`main-${source.textDocument.uri}-${source.textDocument.version}`); for (let index = 0; index < documents.length; index++) { const doc = documents[index]; result ^= (0, hash_1.hash)(`${doc.textDocument.uri}-${doc.textDocument.version}`); result = result >>> 0; } return result; } registerCacheKey(key, documentUri) { this.flushCacheKey(documentUri); this.keyToDocumentUriMap.set(documentUri, key); } flushCacheKey(documentUri) { const key = this.keyToDocumentUriMap.get(documentUri); if (key) { this.typeDocuments.delete(key); this.keyToDocumentUriMap.delete(documentUri); } } flushCache() { this.typeDocuments.clear(); } } exports.DocumentMergerCache = DocumentMergerCache; //# sourceMappingURL=document-merger-cache.js.map