1 function res = cache(command, fn, varargin)
2 %
function res = cache(command, fn, varargin)
4 %
function simulating a ram-disk.
6 % D = cache(
'load',
'myfile') : loading of myfile from cache. If not
7 % in cache, the real file is loaded. Take
8 % care: if the file is changed while data is
9 % in cache, this is not detected!
10 % D = cache(
'clear',
'myfile') : clearing myfile from cache.
11 % D = cache(
'clear') : the whole cache is cleared.
12 % cache(
'save',
'myfile', data): saving data to myfile in
13 % cache, no real saving to disk is performed!
14 % list = cache(
'list') : return list of current entries
15 % res = cache(
'exist',fn) : 1 if dataset exists in cache, 0 otherwise
16 % cache(
'limit',limsize) : sets the size limit to limsize (in byte)
19 % Bernard Haasdonk 23.8.2007
21 persistent keys data limsize
27 %i = find(ismember(keys,fn));
34 if length(keys{j})==length(fn) & ...
45 if length(keys{j})==length(fn) & ...
63 if length(keys{j})==length(fn) & ...
70 data{i} = varargin{1};
72 data{end+1} = varargin{1};
78 if nargin < 2 % clear all entries
82 else % clear entries matching with filename
85 if length(keys{j})==length(fn) & ...
91 j = ones(1,length(keys))
106 error('command unknown')
112 disp(['warning: cache size ',num2str(su),' bytes exceeds limit. Delete entries or rise limit.']);