0.1.0 • Published 7 years ago

@mizchi/cache-strategy v0.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

cache-strategy

npm.io

State cashing by routing.

This is focusing react ssr.

Install

npm install @mizchi/cache-strategy --save
# or
yarn add @mizchi/cache-strategy

Example

import createCacher from 'cache-strategy'

const strategies = [
  {
    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: 1 * 1000
  }
]

const func = async input => {
  return {
    url: input.url,
    createdAt: Date.now()
  }
}

const cacher = createCacher(myStrategies, func)
;(anync () => {
  const data = await cacher({url: '/items/aaa'})
  console.log(data)
})()

License

MIT