UNPKG

rrule-rust

Version:

RRule implementation for browsers and Node.js written in Rust

49 lines (48 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OperationCache = void 0; class OperationCache { constructor({ disabled }) { this._disabled = disabled; this.store = new Map(); } get disabled() { return this._disabled; } getOrSet(key, defaultValue) { if (this.disabled) { return defaultValue; } if (this.store.has(key)) { return this.store.get(key); } this.store.set(key, defaultValue); return defaultValue; } getOrCompute(key, compute) { if (this.disabled) { return compute(); } if (this.store.has(key)) { return this.store.get(key); } const value = compute(); this.store.set(key, value); return value; } disable() { this._disabled = true; } enable() { this._disabled = false; } clear() { this.store.clear(); } clone() { return new OperationCache({ disabled: this.disabled, }); } } exports.OperationCache = OperationCache;