UNPKG

schematic-kafka

Version:

Encode and decode kafka messages with Confluent Schema Registry (pure typescript implementation)

24 lines (23 loc) 1.41 kB
/** * Class that provides a caching wrapper for functions */ export declare class FunctionCacher { private cache; /** * Clear all cached values or a single cached value * @param key (optional) key to remove from the cache. If omitted the complete cache is evicted */ clear(key?: string): void; /** * Create a function proxy that caches the function's result. * The key for the cache value is generated from the function arguments. * The values that should be used for the cache key are provided as the second argument. * @param {function} functionToCache the function that will be wrapped * @param {[boolean]} useArgumentForCache an array of booleans the size of the function arguments. Each item represents the corresponding argument in the functionToCache. * @param context a context to run the functionToCache in. This is relevant if for example the function is a class method and it must have access to other class properties / methods. * @returns {function} function with the same signature as the functionToCache */ createCachedFunction<FnToCacheResponse extends (...args: Array<any>) => ReturnType<FnToCacheResponse>>(functionToCache: FnToCacheResponse, useArgumentForCache: { [key in keyof FnToCacheResponse]: boolean; }, context?: any): (...args: Parameters<FnToCacheResponse>) => ReturnType<FnToCacheResponse>; }