0.0.3 • Published 2 years ago
async-cache-fn v0.0.3
async-cache-fn
Usage
import { asyncCacheFn } from 'async-cache-fn'
export const getData = asyncCacheFn(async (url) => {
const data = await fetch(url)
return await data.json()
})
const users = await getData('/users')
const posts = await getData('/posts')
// in other place, `/users` will only be requested once and the result will be cached.
const users2 = await getData('/users')
Sponsors
License
MIT License © 2022 Anthony Fu