0.2.1 • Published 7 years ago

route-cache-strategy v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

route-cache-strategy

npm.io

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

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago