diff options
Diffstat (limited to 'lib/unstable-cache.ts')
| -rw-r--r-- | lib/unstable-cache.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/unstable-cache.ts b/lib/unstable-cache.ts new file mode 100644 index 00000000..c17bb9d8 --- /dev/null +++ b/lib/unstable-cache.ts @@ -0,0 +1,19 @@ +/** + * @see https://github.com/ethanniser/NextMaster/blob/main/src/lib/unstable-cache.ts + */ + +import { cache } from "react" +import { unstable_cache as next_unstable_cache } from "next/cache" + +// next_unstable_cache doesn't handle deduplication, so we wrap it in React's cache +export const unstable_cache = <Inputs extends unknown[], Output>( + cb: (...args: Inputs) => Promise<Output>, + keyParts: string[], + options?: { + /** + * The revalidation interval in seconds. + */ + revalidate?: number | false + tags?: string[] + } +) => cache(next_unstable_cache(cb, keyParts, options)) |
