-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdp_node_io_cache.m
31 lines (24 loc) · 931 Bytes
/
dp_node_io_cache.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
classdef dp_node_io_cache < dp_node
% dp_node_io_cache caches the full list of outputs.
% When get_iterable is called, if the cache is empty it calls the parent's
% get_iterable, stores the result, and returns it. Otherwise, it returns the cached outputs.
properties
cache = {}; % An empty cell array means no cache is stored.
end
methods
function outputs = get_iterable(obj)
if isempty(obj.cache)
outputs = get_iterable@dp_node(obj);
obj.cache = outputs;
obj.log(1, 'Cached %d outputs from parent.', numel(outputs));
else
outputs = obj.cache;
obj.log(1, 'Returning %d cached outputs.', numel(outputs));
end
end
function clear_cache(obj)
obj.cache = {};
obj.log(1, 'Cache cleared.');
end
end
end