@btc-vision/bsi-common
Version:
Common library for OP_NET.
19 lines (18 loc) • 514 B
JavaScript
import NodeCache from 'node-cache';
export class NodeCacheStrategy {
constructor(maxItems = 1024) {
this.maxItems = 0;
this.cache = new NodeCache();
this.maxItems = maxItems;
}
async get(key) {
return this.cache.get(key);
}
set(key, value, ttl = 0) {
if (this.cache.keys().length > this.maxItems) {
const firstKey = this.cache.keys()[0];
this.cache.del(firstKey);
}
return this.cache.set(key, value, ttl);
}
}