UNPKG

@arathron/n8n-nodes-zoho-books

Version:

n8n community nodes for Zoho Books and Zoho Inventory API integration - Complete CRUD operations for Sales Orders, Invoices, Items, Vendors, Credit Notes, Payments, Purchase Orders, Bills, Composite Items, Tax Management, Tax Groups, and Tax Exemptions

103 lines 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cache = void 0; exports.getCached = getCached; exports.setCached = setCached; exports.delCached = delCached; exports.delCachedPattern = delCachedPattern; exports.clearCache = clearCache; exports.getCacheStats = getCacheStats; exports.cleanupCache = cleanupCache; class TTLCache { cache = new Map(); defaultTTL = 3600_000; get(key) { const entry = this.cache.get(key); if (!entry) { return undefined; } if (Date.now() > entry.expires) { this.cache.delete(key); return undefined; } return entry.data; } set(key, data, ttlMs = this.defaultTTL) { const now = Date.now(); this.cache.set(key, { data, expires: now + ttlMs, created: now, }); } delete(key) { return this.cache.delete(key); } deletePattern(pattern) { const regex = new RegExp(pattern.replace('*', '.*')); const keysToDelete = []; for (const key of this.cache.keys()) { if (regex.test(key)) { keysToDelete.push(key); } } keysToDelete.forEach(key => this.cache.delete(key)); } clear() { this.cache.clear(); } getStats() { const total = this.cache.size; const now = Date.now(); let expired = 0; let valid = 0; for (const entry of this.cache.values()) { if (now > entry.expires) { expired++; } else { valid++; } } return { total, valid, expired, hitRate: total > 0 ? (valid / total) * 100 : 0, }; } cleanup() { const now = Date.now(); let removed = 0; for (const [key, entry] of this.cache.entries()) { if (now > entry.expires) { this.cache.delete(key); removed++; } } return removed; } } exports.cache = new TTLCache(); function getCached(key) { return exports.cache.get(key); } function setCached(key, data, ttlMs) { exports.cache.set(key, data, ttlMs); } function delCached(key) { return exports.cache.delete(key); } function delCachedPattern(pattern) { exports.cache.deletePattern(pattern); } function clearCache() { exports.cache.clear(); } function getCacheStats() { return exports.cache.getStats(); } function cleanupCache() { return exports.cache.cleanup(); } //# sourceMappingURL=Cache.js.map