Memoize promise-returning functions.
const Cache = require('promise-cache-memorize')('redis')
const requestWithCache = Cache.remember('request', request)
Factory function that configuring and returning actual Cache
object.
-
type - cache backend. Current support
simple
,lru
orredis
-
options - cache backend configuration.
-
timeout - (default: 3600) cache expire timeout, 1 hour by default
-
if it is redis backend, see ioredis document
-
if it is lru backend, see lru document
-
Memorize promise-returning functions fn
with key
.
- fn - function that returning promise.
- key - string using as cache key.
- maxAge - (default: options.timeout) cache expired after
maxAge
seconds.
const request = require('request-promise')
const Cache = require('promise-cache-memorize')('redis')
const requestWithCache = Cache.remember('request', request)
function sendRequest () {
return requestWithCache('http://httpbin.org/get')
}
sendRequest().then((res) => {
console.log(res)
// hit cache
sendRequest().then((res) => {
console.log(res)
})
})
- Provide options for cache type
- Multiple cache backend support
MIT