UNPKG

@daisugi/kintsugi

Version:

Kintsugi is a set of utilities to help build a fault tolerant services.

29 lines 858 B
import { Result } from '@daisugi/anzen'; import { Ayamari } from '@daisugi/ayamari'; const { errFn } = new Ayamari(); export class SimpleMemoryStore { #store; constructor() { this.#store = Object.create(null); } get(cacheKey) { const value = this.#store[cacheKey]; if (typeof value === 'undefined') { return Result.failure(errFn.NotFound('Not found in cache.')); } return Result.success(value); } set(cacheKey, value) { this.#store[cacheKey] = value; return Result.success(value); } delete(cacheKey) { this.#store[cacheKey] = undefined; return Result.success(cacheKey); } weakDelete(cacheKey) { this.#store[cacheKey] = undefined; return Result.success(cacheKey); } } //# sourceMappingURL=simple_memory_store.js.map