mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-02 19:26:11 +01:00
Use React’s cache to avoid some queries to the database
This commit is contained in:
17
src/app/cached-functions.ts
Normal file
17
src/app/cached-functions.ts
Normal file
@@ -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),
|
||||
}
|
||||
Reference in New Issue
Block a user