@daisugi/kintsugi
Version:
Kintsugi is a set of utilities to help build a fault tolerant services.
33 lines • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleMemoryStore = void 0;
const anzen_1 = require("@daisugi/anzen");
const ayamari_1 = require("@daisugi/ayamari");
const { errFn } = new ayamari_1.Ayamari();
class SimpleMemoryStore {
#store;
constructor() {
this.#store = Object.create(null);
}
get(cacheKey) {
const value = this.#store[cacheKey];
if (typeof value === 'undefined') {
return anzen_1.Result.failure(errFn.NotFound('Not found in cache.'));
}
return anzen_1.Result.success(value);
}
set(cacheKey, value) {
this.#store[cacheKey] = value;
return anzen_1.Result.success(value);
}
delete(cacheKey) {
this.#store[cacheKey] = undefined;
return anzen_1.Result.success(cacheKey);
}
weakDelete(cacheKey) {
this.#store[cacheKey] = undefined;
return anzen_1.Result.success(cacheKey);
}
}
exports.SimpleMemoryStore = SimpleMemoryStore;
//# sourceMappingURL=simple_memory_store.js.map