%% Change Cache Size of Memoized Function
% Create a MemoizedFunction object by memozing the datetime function.

mf = memoize(@datetime)

% Change the maximum number of cached input and output combinations.

mf.CacheSize = 2

% Call the memoized function with three different input values.

a = mf('today');
b = mf('yesterday');
c = mf('tomorrow');

% Call the stats function to investigate the cached results.

s = stats(mf);
s.Cache.Inputs{:}

% The results of calling the memoized function with 'today' are not cached because the CacheSize is 2.
% Copyright 2012 The MathWorks, Inc.