import QuickLRU, { Options } from 'quick-lru-cjs'; import { BautaJSInstance, Context, Pipeline } from '../types'; export interface Normalizer { (prev: TIn, ctx: Context, bautajs: BautaJSInstance): CacheKey; } export interface CacheStepFunction extends Pipeline.StepFunction { store: QuickLRU; } /** * Cache the given OperationFunction or pipeline. * If maxAge is provided the module tinyLRU will be used to allow the items to expired. * If only maxSize or non option is provided the module hashlru will be used to improve the speed. * @export * @template TIn * @template TOut * @template CacheKey * @param {Pipeline.StepFunction} pipeline * @param {Normalizer} [normalizer=(prev: TIn) => hash(prev)] * @param {Options} options * @param {Number} [options.maxAge=0] Milliseconds an item will remain in cache; lazy expiration upon next get() of an item. With 0 items never expires. * @param {Number} options.maxSize=500 Max number of items on cache. * @return {CacheDecoratorFunction} An operation function that you can plug in on a `bautajs` pipeline. * @example * import { pipe, createContext, cache } from '@axa/bautajs-core'; * * function createAKey(prev, ctx, bautajs) { * ctx.data.myKey = 'mykey'; * } * * function doSomethingHeavy(prev, ctx, bautajs) { * let acc = 0; * for(let i=0; i < 1000000000; i++) { * acc += i; * } * * return acc; * } * * const myPipeline = pipe( * createAKey, * doSomethingHeavy * ); * * const cacheMyPipeline = cache(myPipeline, (prev, ctx) => ctx.data.myKey, { maxSize:3 }); * * const result = await cacheMyPipeline(null, createContext({})); * console.log(result); */ export declare function cache(fn: Pipeline.StepFunction, options: Options, normalizer?: Normalizer): CacheStepFunction; //# sourceMappingURL=cache.d.ts.map