clearAllMemoizedCaches
Empties the caches of all memoized functions at once.
Category: Software Development Tools > Performance and Memory
Syntax
clearAllMemoizedCaches
Discards every stored result of every function created with memoize.
Description
A function made with memoize remembers the outputs for the inputs it has already seen. clearAllMemoizedCaches wipes those stored results for every memoized function in the session, so the next call with any input recomputes. The functions stay memoized and keep their settings, only the cache contents and the hit and miss counters go back to zero.
Use it to free memory or to be sure that a later timing is not served from a cache. To empty only one function, call clearCache on it.
Example
Reset every cache
f = memoize(@(x) x^2);
f(2); f(2);
s = stats(f);
fprintf('hits %d, misses %d\n', s.Cache.TotalHits, s.Cache.TotalMisses)
clearAllMemoizedCaches
s = stats(f);
fprintf('hits %d, misses %d\n', s.Cache.TotalHits, s.Cache.TotalMisses)
Output
hits 1, misses 1
hits 0, misses 0