The redis cache instance.
The key inside the redis
instance, where the fetched value will be stored.
The original function, that fetches the data.
Optional
options: Nilable<ICreateRedisCacheFetcherOptions>Custom options.
The new, wrapped function.
import axios from "axios"
import RedisCache from "@egomobile/redis"
const cache = new RedisCache()
const loadRandomUsers = createRedisCacheFetcher(
cache,
'randomUsersKey',
async (seed: string) => {
const response = await axios.get(`https://randomuser.me/api/?seed=${encodeURIComponent(seed)}`)
return response.data
}
)
// first call MUST be successful, otherwise
// exception is re-thrown
const data1 = await loadRandomUsers("foobar1")
// should be same as `data1`, because it is cached
const data2 = await loadRandomUsers("foobar2")
// reset and force reloading data
await loadRandomUsers.reset()
const data3 = await loadRandomUsers("foobar3")
Generated using TypeDoc
Wraps a function, that fetches and caches a value, using a
RedisCache
instance. The signature of the original function will be kept.