hypertune
Version:
[Hypertune](https://www.hypertune.com/) is the most flexible platform for feature flags, A/B testing, analytics and app configuration. Built with full end-to-end type-safety, Git-style version control and local, synchronous, in-memory flag evaluation. Opt
32 lines • 891 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// LRUCache relies on the fact that Map stores keys in their insertion order.
class LRUCache {
constructor(maxSize) {
this.maxSize = maxSize;
this.cache = new Map();
}
get(key) {
if (!this.cache.has(key)) {
return null;
}
const value = this.cache.get(key);
// Refresh key.
this.cache.delete(key);
this.cache.set(key, value);
return value;
}
set(key, value) {
this.cache.delete(key);
while (this.cache.size >= this.maxSize) {
// Evict last used key.
this.cache.delete(this.cache.keys().next().value);
}
this.cache.set(key, value);
}
purge() {
this.cache = new Map();
}
}
exports.default = LRUCache;
//# sourceMappingURL=LRUCache.js.map