function memoizer by using redis cache
Lodash memoizing have problem about memory leak states here:
So I write a new memoizer using redis and TTL to ensure memory not leaking
npm install redis-memoize-function
You can memoize function by using this pattern
function originalFunction () {
return 555
}
memoizer.connectRedis('redis://127.0.0.1:6379')
const memoizeFunc = memoizer.memoize(originalFunction)
const res1 = await memoizeFunc()
assert(res1 === 555)
Please beware that you cannot memoize
- Anonymous function (will throw)
- Functions with same name