List all memoized function caches
Show older comments
I know that clearAllMemoizedCaches will clear all memoized function data, but what if I just want to list all existing memoized caches (and maybe also their cache stats). Is there a way to do that?
Accepted Answer
More Answers (1)
Hi Matt,
Is evalin acceptable?
clearvars
clearAllMemoizedCaches;
mf1a = memoize(@func1);
mf1b = memoize(@func1);
mf2 = memoize(@func2);
for ii = 1:10,mf1a(ii);mf2(ii);end
a = pi;
w = whos;
w = w(strcmp({w.class},'matlab.lang.MemoizedFunction'));
s = arrayfun(@(w) evalin('base',"stats(" + w.name + ")"),w);
names = {w.name};
[s(:).Name] = names{:}
function func1(x)
x;
end
function func2(x)
x;
end
3 Comments
The question was clear enough. I just misunderstood it.
After some poking around, I think you can get what you want (i.e., a list of function handles) using some undocumented (yet easily found) and unrecommended (yet discussed here on this forum) functionality (I don't see any documented way to do it). Not sure if it would be appropriate to post here. Are there any guidelines for such things?
clearAllMemoizedCaches is an m-function (at least in 2024a) and I was able to start from there and get the information you seek.
Matt J
7 minutes ago
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!