UNPKG

@httpc/kit

Version:

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

14 lines (13 loc) 449 B
import assert from "assert"; import { injectWithTransform } from "tsyringe"; import { KEY } from "../di"; export function cache(key, options) { return injectWithTransform(KEY("ICachingService"), GetCacheTransform, key, options); } class GetCacheTransform { transform(service, key, options) { const cache = service.getCache(key, options); assert(cache, `No cache for key '${key}'`); return cache; } }