// 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 = ( fn: (...params: P) => Promise, keys: Parameters[1], opts: Parameters[2] ) => { const wrap = async (params: unknown[]): Promise => { const result = await fn(...(params as P)); return stringify(result); }; const cachedFn = unstable_cache(wrap, keys, opts); return async (...params: P): Promise => { const result = await cachedFn(params); return parse(result); }; };