summaryrefslogtreecommitdiff
path: root/lib/unstable-cache.ts
blob: c17bb9d8f939c3cba6bc43a93d5d2aa03864a321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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))