UNPKG

@croct/cache

Version:

An abstraction layer for caching.

23 lines (22 loc) 600 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrefixedCache = void 0; /** * A cache that prefixes keys with a string. */ class PrefixedCache { constructor(inner, prefix) { this.inner = inner; this.prefix = prefix; } get(key, loader) { return this.inner.get(`${this.prefix}/${key}`, () => loader(key)); } set(key, value) { return this.inner.set(`${this.prefix}/${key}`, value); } delete(key) { return this.inner.delete(`${this.prefix}/${key}`); } } exports.PrefixedCache = PrefixedCache;