diff options
| author | Sebastien Castiel <sebastien@castiel.me> | 2024-01-29 22:37:13 -0500 |
|---|---|---|
| committer | Sebastien Castiel <sebastien@castiel.me> | 2024-01-30 12:57:21 -0500 |
| commit | 9e300e0ff0c9d93cbaeaa86c1e2a560523107382 (patch) | |
| tree | ebeaea60117fbac781a415e3299395f3f8e637d7 /src/app/cached-functions.ts | |
| parent | 3847a67a192a04098643e19953549a99ca152b8a (diff) | |
Use React’s cache to avoid some queries to the database
Diffstat (limited to 'src/app/cached-functions.ts')
| -rw-r--r-- | src/app/cached-functions.ts | 17 |
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), +} |
