Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about "No weak-mappable object" #3

Open
nohira opened this issue Jan 20, 2020 · 1 comment
Open

Question about "No weak-mappable object" #3

nohira opened this issue Jan 20, 2020 · 1 comment

Comments

@nohira
Copy link

nohira commented Jan 20, 2020

Hi,

Thanks for your library and documentation. It's very nice to find a library which explains what and how it solves some cache performance issues.
I've fully understood how it works now. All my arguments are objects and there is no non weak mappable objects as arguments when I call my selector.

I still have an issue concerning a selector which compute a result from multiple sub selectors which return all non weak mappable object (all booleans), and have an error.

In your documentation, you mention to use an external cache object but I guess, it should not be a global object that will never be unreferenced as it cache will never be cleared.

If I understand well, it will be better to have a weak mappable object, which also have his lifecycle and will be garbage collected to have my values being cached while this object still exist.

Am I right?

@theKashey
Copy link
Owner

Yes, you are correct.
The idea is to have an unique object, you can use as key for computations. The problem is - only one such object could be used as a key, so when times comes to "compose" different keys together memoization might fall (I should provide a helper to mitigate this).

However, sooner or later, you might end with all non weak mappable object (all booleans), or numbers/strings. That's ok, but do you need memoization for those calculations? Is there any complex medium to work out - all inputs are simple.

I know - some string calculations, as well as Fibonacci numbers, could be very CPU intense, but you will have use other memoization technology, with explicits cache, to handle them, not kashe.
That's the hard limitation of this library. Which makes your live easier.

There is also a case, when you are returning an object from such "complex" function - const getResult = (a,b) => ({a,b}) - and want that object to be "constant". Just use lodash, not try to overthink it - usually there are limited number of combinations, and you would experience no problem with the cache. 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants