How is the entire memoize cache deleted in lodash?

Lodash doesn't provide a way to delete cache of all memoized functions. You have to do it one by one. It's because every memoized function has its own cache object instance.

Look at lodash memoize source code:

function memoize(func, resolver) {
  var memoized = function() {
    // ...
  }
  memoized.cache = new (memoize.Cache || MapCache);
  return memoized;
}

The GitHub discussions you referred to are about clearing cache of a single memoized function.

You can keep all memoized functions into an array so that it's able to iterate over them and clear cache one by one.

const func1 = _.memoize(origFunc1);
const func2 = _.memoize(origFunc2);

const memoizedFunctions = [];
memoizedFunctions.push(func1);
memoizedFunctions.push(func2);   

// clear cache of all memoized functions
memoizedFunctions.forEach(f => f.cache = new _.memoize.Cache);

update answer in 2019 :), lodash has added clear function to cache method so the way to clear cache can be

memoizedFunctions.forEach(f => f.cache.clear());

tested lodash version 4.17.13


function _printName(name) {
  console.log(name);
}

const printName = _.memoize(_printName);

printName("David");
printName("John");

To clear the entire memoized cache (both David and John):

printName.cache.clear();

To explicitly remove a single memoized object:

printName.cache.delete("David");