medikoo / memoizee

Complete memoize/cache solution for JavaScript
ISC License
1.73k stars 61 forks source link

How cache could be not saved in some cases? #102

Closed GlebDolzhikov closed 5 years ago

GlebDolzhikov commented 5 years ago

I use memoizee in redux selectors. Some time i understand that i shouldn't save this result to cache, but include same computation to the normalizer don't make any sens. I read about promises that not saved on reject but my function is synchronous and i glad to keep it as it is, how can i not write cache!

Thanks.

medikoo commented 5 years ago

See: https://github.com/medikoo/memoizee#manual-clean-up

GlebDolzhikov commented 5 years ago

But how can i do this if the cache wasn't written at this moment?

medikoo commented 5 years ago

But how can i do this if the cache wasn't written at this moment?

If you ask whether you can prevent storing value in cache (instead of deleting it right after it's stored) then that (composition-wise) should be configured on top of memoized function (there's no way to force it internally), so:


const someFunctionMemoized = memoizee(someFunction);

const targetFunction = (arg) => {
  if (shouldResultBeMemoized(arg)) return someFunctionMemoized(arg);
  return someFunction(arg);
};
GlebDolzhikov commented 5 years ago

yeah, probably i need put this checks before invocation, thanks for your answers!