UNPKG

@httpc/kit

Version:

httpc toolbox for building function-based API with minimal code and end-to-end type safety

33 lines (32 loc) 821 B
export class PrefixCacheDecorator { constructor(prefix, provider) { this.prefix = prefix; this.provider = provider; } *keys() { for (const key of this.provider.keys()) { yield this._un_prefix(key); } } has(key) { return this.provider.has(this._prefix(key)); } get(key) { return this.provider.get(this._prefix(key)); } set(key, value) { return this.provider.set(this._prefix(key), value); } delete(key) { return this.provider.delete(this._prefix(key)); } clear() { throw new Error("not-supported"); } _prefix(key) { return `${this.prefix}:${key}`; } _un_prefix(key) { return key.substring(this.prefix.length + 1); } }