medikoo / memoizee

Complete memoize/cache solution for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How cache could be not saved in some cases?

GlebDolzhikov opened this issue · comments

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.

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

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);
};

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