summaryrefslogtreecommitdiff
path: root/lib/unstable-cache.ts
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
committerjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
commit1a2241c40e10193c5ff7008a7b7b36cc1d855d96 (patch)
tree8a5587f10ca55b162d7e3254cb088b323a34c41b /lib/unstable-cache.ts
initial commit
Diffstat (limited to 'lib/unstable-cache.ts')
-rw-r--r--lib/unstable-cache.ts19
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))