@viestimedia/cachified-ioredis-adapter
v1.0.4
Published
ioredis adapter for cachified
Downloads
24
Readme
ioredis adapter for Cachified
Setup
Install with npm i @viestimedia/cachified-ioredis-adapter
.
import { cachified as c, CachifiedOptions } from '@epic-web/cachified';
import { ioredisAdapter } from '@viestimedia/cachified-ioredis-adapter';
export function cachified<Value>(options: Omit<CachifiedOptions<Value>, 'cache'>) {
return c({
cache: ioredisAdapter(redis, {
logErrors: process.env.NODE_ENV === 'production',
throwErrors: process.env.NODE_ENV !== 'production',
}),
...options,
});
}
Usage
const data = await cachified({
key: 'something',
ttl: 1000 * 60 * 60 * 24,
async getFreshValue() {
console.info(`Fetching fresh data`)
const res = await fetch(process.env.API_URL)
return res.json()
},
})
Licence
MIT