simple-node-memory-cache
Version:
In-memory object cache written in typescript for Node that supports multiple eviction strategies.
39 lines (38 loc) • 1.61 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Cache_1 = require("./cacheBase/Cache");
var SimpleFIFO = /** @class */ (function (_super) {
__extends(SimpleFIFO, _super);
function SimpleFIFO() {
return _super !== null && _super.apply(this, arguments) || this;
}
SimpleFIFO.prototype.get = function (key) {
return this.update(key, (this.cache.get(key)));
};
SimpleFIFO.prototype.set = function (key, value) {
if (this.length() >= this._maxObjectsInCache && !this.has(key)) {
// Definine eviction strategy.
}
return this.cache.set(key, [value, Date.now(), 0]);
};
SimpleFIFO.prototype.update = function (key, value) {
// If anything needs to be updated when a records is retrieved to make the eviction strategy
// work correctly then place it here.
return value;
};
return SimpleFIFO;
}(Cache_1.SimpleCache));
exports.SimpleFIFO = SimpleFIFO;