Comments (6)
@dheera I've faced a similar problem today when solving a data inconsistency bug, what I understand is that this library does not honor dict args however I was able to fix it by providing { length: false }
argument like this: export const getData = memoizee(getDataRaw, { length: false });
,
This actually caused a pretty big problem for us because we were getting incorrect data.
@medikoo can you please shine some light here? Is this package actively maintained? If I open a PR to fix this would you able to review/approve and rerelease?
from memoizee.
@dheera @dankolesnikov I'm not sure how I missed this issue (btw, yes this package is maintained). Sorry for responding so late
Yes, currently there's no dedicated option for that, but it can be achieved relatively simply. See: https://github.com/medikoo/memoizee/blob/master/README.md#memoizing-on-dictionary-object-hash-arguments
from memoizee.
thank you so much for a quick response @medikoo !
- I am curious why not support this functionality out of the box? is there a design intention around that?
- Could you please explain why does this solution make things work?
memoizee(getDataRaw, { length: false });
The function signature is ofgetRawData
:
const getDataRaw = (effectiveDate: Date, filter: Record<string, any> | Knex.QueryCallback = {}) => {...}
Additionally, @dheera @medikoo I've realized that the cause for my bug stemmed from the fact that filter
argument had a default value rather than being an object/dict, if I remove that everything works.
@medikoo The problem I face is that I am dealing with auto-generated code and I don't have good control of the arguments (and their ordering) of the functions I pass into memoizee
, hence the solution you linked might not work well normalizer: function(args) { // args is arguments object as accessible in memoized function return JSON.stringify(deepSortedEntries(args[0])); }
, here args[0]
is problematic for me as I don't know the position of the arguments that's dict.
Refactoring the entire code base to remove the default value is also not realistic but could you please explain why { length: false }
makes everything work? That would be the easiest solution for me but it's critical I understand the implications of this parameter. Thank you again!
from memoizee.
I am curious why not support this functionality out of the box? is there a design intention around that?
I think it might be nice to support it out of the box, but when we speak of well designed generic solution, it may appear it's not trival to implement, e.g. we may want to go beyond JSON, to e.g. support well types as BigInt, etc. or recognise properly non JSON objects in collection (while after JSON stringification they're just cleared).
You've already noticed that plain simple solution as proposed in docs, is too optimistic for your case
So main problems I see is:
- It's time taking to make it right (have a well thought general approach).
- Current codebase is pretty old, and I'd prefer to refactor it into v1, before adding new functionalities (see: #73)
Could you please explain why does this solution make things work?
Sorry, I don't understand this question
here args[0] is problematic for me as I don't know the position of the arguments that's dict.
In that case I believe you need to normalize against whole args
and not just args[0]
from memoizee.
@medikoo Thank you so much for quick replies!
I've turned export const getData = memoizee(getDataRaw);
into export const getData = memoizee(getDataRaw, { length: false });
and it fixed all my problems with dict argument not working correctly but I don't fully understand why, documentation is not very clear. Can you please shine some light on what does { length: false }
do under the hood?
from memoizee.
I've turned export const getData = memoizee(getDataRaw); into export const getData = memoizee(getDataRaw, { length: false }); and it fixed all my problems with dict argument
I see. length: false
, changes the approach on what arguments are taken into account when memoizing.
If function signature is (effectiveDate, filter: {}
, then memoization is evaluated against only first argument (as function length is 1
), with false
, memoizer always takes all passed arguments and evaluates on that. It's documented here: https://github.com/medikoo/memoizee#arguments-length
from memoizee.
Related Issues (20)
- Promise rejections not cleared immediately from cache HOT 2
- Callback for cache access HOT 5
- setter method HOT 1
- Rollup fails to bundle memoizee correctly HOT 6
- feat: let default nomalizer be more general HOT 1
- replace `es5-ext` with `core-js@^3` HOT 2
- Cannot import memoizee HOT 3
- Memoizing a function without arguments HOT 1
- Allow `maxAgeSinceAccess` in addition to `maxAge` HOT 11
- Why is the memoizee so slow? HOT 2
- Is there a way to dynamically configure the size? HOT 7
- Feature Request: Wouldn't it be good if we could use a Redis backend? HOT 2
- max option does not work with promise option HOT 1
- Option to return prior cached value on update failure HOT 5
- Package is showing a vulnerability HOT 7
- [email protected] is broken due to node requirement HOT 10
- typo in engines.node HOT 20
- Found a mistake here that breaks our Pipeline HOT 2
- Codecov badge HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from memoizee.