Continuous error in logs with cache-manager 2.9.1: TypeError: work is not a function
kishorgandham opened this issue · 5 comments
Nodejs 10.16.0
NPM 6.9.0
OS: Ubuntu 16.04LTS
After upgrading cache-manager to 2.9.1 from 2.6.0, the following error is coming in logs:
TypeError: work is not a function
at onResult (/mnt/pd1/shopalyst/privatebeta-core/mira-nodejs/node_modules/cache-manager/lib/caching.js:196:20)
at process._tickCallback (internal/process/next_tick.js:61:11)
TypeError: work is not a function
at onResult (/mnt/pd1/shopalyst/privatebeta-core/mira-nodejs/node_modules/cache-manager/lib/caching.js:196:20)
at process._tickCallback (internal/process/next_tick.js:61:11)
TypeError: work is not a function
at onResult (/mnt/pd1/shopalyst/privatebeta-core/mira-nodejs/node_modules/cache-manager/lib/caching.js:196:20)
at process._tickCallback (internal/process/next_tick.js:61:11)
TypeError: work is not a function
at onResult (/mnt/pd1/shopalyst/privatebeta-core/mira-nodejs/node_modules/cache-manager/lib/caching.js:196:20)
at process._tickCallback (internal/process/next_tick.js:61:11)
TypeError: work is not a function
at onResult (/mnt/pd1/shopalyst/privatebeta-core/mira-nodejs/node_modules/cache-manager/lib/caching.js:196:20)
at process._tickCallback (internal/process/next_tick.js:61:11)
TypeError: work is not a function
at onResult (/mnt/pd1/shopalyst/privatebeta-core/mira-nodejs/node_modules/cache-manager/lib/caching.js:196:20)
at process._tickCallback (internal/process/next_tick.js:61:11)
TypeError: work is not a function
at onResult (/mnt/pd1/shopalyst/privatebeta-core/mira-nodejs/node_modules/cache-manager/lib/caching.js:196:20)
at process._tickCallback (internal/process/next_tick.js:61:11)
I use cache-manager in a nodejs server side app.
Sorry for the delay. I hope you were able to figure this out. If not, then can you supply more info about how you're using cache-manager?
Hello. I could reproduce it on latest version as well. I noticed that it happen when I use wrap with a TTL. When I remove it, the module works as expected.
To reproduce:
const cacheManager = require("cache-manager");
const memoryCache = cacheManager.caching({store: 'memory', max: 200, ttl: 60 });
const item = memoryCache.wrap(1, function () {
return Promise.resolve(1);
}, 60); // <= when TTL is provided, the error triggers. Remove the TTL and the module works as expected.
On latest v2
/dev/github.com/xxx/node_modules/cache-manager/lib/caching.js:196
return work(function(err, data) {
^
TypeError: work is not a function
at onResult (/dev/github.com/xxx/node_modules/cache-manager/lib/caching.js:196:20)
On v3.2.1:
/dev/github.com/xxx/node_modules/cache-manager/lib/caching.js:255
return work(function(err, data) {
^
TypeError: work is not a function
at onResult (/dev/github.com/xxx/node_modules/cache-manager/lib/caching.js:255:20)
The fix for this is to pass the ttl
like this: {ttl: 60}
. I added a test in the develop branch to show that this works: 45b1ce0#diff-4a20e938ab2b17c80738ff5ba5ca036dR1482
Ha indeed, thank you. I overlooked the README here and based myself on the README of Mongodb store, my bad.
Thanks for pointing it out 🙇
No problem! I think node-cache-manager
may have accepted a number instead of an object for the ttl
at one point, so I wasn't sure myself.