@directus/api
Version:
Directus is a real-time API and App dashboard for managing SQL database content
13 lines (12 loc) • 734 B
TypeScript
/**
* Wraps a function with caching capabilities.
*
* @param namespace - A unique namespace for the cache key.
* @param handler - The function to be wrapped.
* @param prepareArg - Optional function to prepare arguments for hashing.
* @returns A new function that caches the results of the original function.
*
* @NOTE Ensure that the `namespace` is unique to avoid cache key collisions.
* @NOTE Ensure that the `prepareArg` function returns a JSON stringifiable representation of the arguments.
*/
export declare function withCache<F extends (...args: any) => any>(namespace: string, handler: F, prepareArg?: (...args: Parameters<F>) => Record<string, unknown>): (...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>;