0.2.1 • Published 7 years ago
route-cache-strategy v0.2.1
route-cache-strategy
State cashing by routing.
This is focusing react ssr.
Install
npm install route-cache-strategy --save
# or
yarn add route-cache-strategy
Example
import createRouteCacher from 'route-cache-strategy'
const myStrategies = [
{
pattern: '/items/:id',
async createCacheKey(params) {
const res = await fetch(`/api/items/${params.id}/updated_at`)
const updated_at = await res.text()
return `items-${params.id}-${updated_at}`
},
expire: 60 * 1000 // it works with only redis
}
]
const func = async input => {
return {
url: input.url,
createdAt: Date.now()
}
}
const cacher = createRouteCacher(myStrategies, func)
;(anync () => {
const data = await cacher({url: '/items/aaa'})
console.log(data)
})()
License
MIT