chaingate
Version:
Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO
23 lines (22 loc) • 630 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TTLCache = void 0;
class TTLCache {
constructor(fn, ttl) {
this.fn = fn;
this.ttl = ttl;
this.cache = null;
this.lastUpdate = null;
}
async fetch() {
// Refresh if cache is empty or TTL has expired
if (!this.lastUpdate || Date.now() > this.lastUpdate + this.ttl) {
const result = await this.fn();
this.cache = result;
this.lastUpdate = Date.now();
return result;
}
return this.cache;
}
}
exports.TTLCache = TTLCache;