You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would allow node-cache to be a drop-in replacement to things that expect a map, for example lodash's memoize which explains:
Note: The cache is exposed as the cache property on the memoized function. Its creation may be customized by replacing the _.memoize.Cache constructor with one whose instances implement the Map method interface of clear, delete, get, has, and set.
I currently have a workaround by doing:
const_=require('lodash');constNodeCache=require('node-cache');// Adapter for NodeCache to have the Map interface expected by lodash.memoizeclassMemoizeCache{constructor(args){this.cache=newNodeCache(args);}clear(){this.cache.flushAll();}delete(key){returnthis.cache.del(key);}get(key){returnthis.cache.get(key);}has(key){returnthis.cache.has(key);}set(key,value){this.cache.set(key,value);returnthis;}}module.exports=(fn,ttl)=>{constmemoized=_.memoize(fn);memoized.cache=newMemoizeCache({stdTTL: ttl});returnmemoized;};
But it would be nice to conform to that interface and not requiring that change.
The text was updated successfully, but these errors were encountered:
https://262.ecma-international.org/7.0/#sec-properties-of-the-map-prototype-object
This would allow node-cache to be a drop-in replacement to things that expect a map, for example lodash's memoize which explains:
I currently have a workaround by doing:
But it would be nice to conform to that interface and not requiring that change.
The text was updated successfully, but these errors were encountered: