aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/cached-functions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/cached-functions.ts')
-rw-r--r--src/app/cached-functions.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/app/cached-functions.ts b/src/app/cached-functions.ts
new file mode 100644
index 0000000..cc148fd
--- /dev/null
+++ b/src/app/cached-functions.ts
@@ -0,0 +1,17 @@
+import { getGroup } from '@/lib/api'
+import { cache } from 'react'
+
+function logAndCache<P extends any[], R>(fn: (...args: P) => R) {
+ const cached = cache((...args: P) => {
+ // console.log(`Not cached: ${fn.name}…`)
+ return fn(...args)
+ })
+ return (...args: P) => {
+ // console.log(`Calling cached ${fn.name}…`)
+ return cached(...args)
+ }
+}
+
+export const cached = {
+ getGroup: logAndCache(getGroup),
+}