aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/cached-functions.ts
blob: cc148fd9cbb7dcb7ebcb7c7b9a528ff7b8d31e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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),
}