medikoo / memoizee

Complete memoize/cache solution for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can't figure out why cache is being hit

SeeThruHead opened this issue · comments

const wrapApiCall = questionId => {
  console.log(`actual api call number = ${questionId}`);
  return get(`/questions/${questionId}`);
};

const questionById = memoize(R.pipeP(
  wrapApiCall,
  R.path(['data', 'data', 'attributes']),
  item => ({
    label: item.subject,
    value: `question::${item.id}`,
    id: item.id,
    category: 'Challenge Questions',
    type: 'question'
  })
));

const wrapped = input => {
  console.log(`called with ${input}`);
  return questionById(input);
};

in my local environment:

called with 71
actual api call number = 71
called with 74
actual api call number = 74
called with 92
actual api call number = 92

NODE_ENV=production (on qa server)

called with 30
actual api call number = 30
called with 2449
called with 34
called with 3986

I wouldn't ask this if i have a clue what was happening, hoping you might have an idea

is there some way to show what's in the cache on every execution? and what memoizee is using to index the cache? a debug mode perhaps?

@SeeThruHead what you shown doesn't expose all the details. Some questions:

  • Memoizee internals decide on caching algorithm basing on function length. What is the length of function that's result of R.pipeP(..) call?
  • What are the arguments (specifically input) with which the memoized function is called? What is this exactly an object? string ?

I'm gonna close this as it's not a bug report or feature request. Still feel free to continue discussion below

thank you for taking the time to help, the function length resulting is 1 and the argument for each call is typeof string

In such case cache hit will only occur if function is called with string it was already called with. There's on other possibility.

If you feel it's otherwise, increase logging (ensure that argument is indeed string) and ensure that indeed function that's put to memoizee has length 1

thank you very much, this very incredibly helpful to track down the offending cause.