UNPKG

@clickup/ent-framework

Version:

A PostgreSQL graph-database-alike library with microsharding and row-level security

40 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VCCaches = void 0; const WeakTicker_1 = require("../internal/WeakTicker"); /** * Holds an auto-expiring map of VC caches. */ class VCCaches extends Map { constructor(expirationMs) { super(); this.expirationMs = expirationMs; } /** * Calls the Map's get() and defers cache clearing to the next WeakTicker * tick (i.e. schedules clearing on inactivity). */ get(key) { if (this.expirationMs > 0) { weakTicker.schedule(this, this.expirationMs); } return super.get(key); } /** * Called periodically after VC#cache() was called at least once. */ onTick(tickNoSinceScheduling) { if (tickNoSinceScheduling === 0) { // Skip the very 1st tick after the most recent scheduling. Starting from // the 2nd tick, we can be sure that query cache hasn't been accessed // within at least expirationMs. return "keep"; } this.clear(); return "unschedule"; } } exports.VCCaches = VCCaches; // Clears VC caches after some time of inactivity. const weakTicker = new WeakTicker_1.WeakTicker(); //# sourceMappingURL=VCCaches.js.map