Files
formbricks-formbricks/packages/lib/cache.ts
Piyush Gupta b016d80cb2 feat: adds enterprise license check (#2431)
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
Co-authored-by: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com>
Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
2024-05-07 13:36:20 +00:00

26 lines
829 B
TypeScript

// cache wrapper for unstable_cache
// workaround for https://github.com/vercel/next.js/issues/51613
// copied from https://github.com/vercel/next.js/issues/51613#issuecomment-1892644565
import { unstable_cache } from "next/cache";
import { parse, stringify } from "superjson";
export { revalidateTag } from "next/cache";
export const cache = <T, P extends unknown[]>(
fn: (...params: P) => Promise<T>,
keys: Parameters<typeof unstable_cache>[1],
opts: Parameters<typeof unstable_cache>[2]
) => {
const wrap = async (params: unknown[]): Promise<string> => {
const result = await fn(...(params as P));
return stringify(result);
};
const cachedFn = unstable_cache(wrap, keys, opts);
return async (...params: P): Promise<T> => {
const result = await cachedFn(params);
return parse(result);
};
};