THE AUDITORY MODELING TOOLBOX

Applies to version: 1.6.0

View the code

Go to function

AMT_CACHE
Caches variables for later or retrieves variables from cache

Usage:

var = amt_cache('get', package, flags);
amt_cache('set', package, variables);

Input parameters:

get gets the content of a package from the cache. variables = amt_cache('get', package) reads a package from the cache and outputs its content in var. package must a be a string identifying the package of variables. If the package contains multiple variables, variables can be a list of variables like [var1, var2, ... , varN] = .... The order of returned variables is the same as that used for saving in cache. ... = amt_cache('get', package, flags) allows to control the behaviour of accessing the cache.
set stores variables as a package in the cache. amt_cache('set', package, variables) saves variables in the cache using the name package. variables can be a list of variables separated by comma.
getURL outputs the URL of the cache in the internet.
setURL sets the URL of the internet cache to a new URL.
clearAll clears the cache directory. An interactive confirmation is required.

Description:

amt_cache is a utility function for avoiding long computation times by retrieving pre-calculated intermediate results from the AMT's online repository.

The following flags can be specified

'normal' Use cached package. If the cached package is locally not available, it will be downloaded from the internet. If it is remotely not available, enforce recalculation of the package. Note that this method may by-pass the actual processing and thus does not always test the actual functionality of a model.
'cached' Enforce to used cached package. If the cached package is locally not available, it will be downloaded from the internet. If it is remotely not available, enforce recalculation of the package. Note that this method may by-pass the actual processing and thus does not always test the actual functionality of a model. It is, however, very convenient for fast access of results like plotting figures. On the internet, the cached packages are available for the release versions only.
'redo' Enforce the recalculation of the package. [..] = amt_cache('get', [..]) outputs empty variables always.
'localonly' Package will be recalculated when locally not available. Do not connect to the internet.

This is an example of using the cache in a function. In this example, we store the variables x, y, and z in the package fileABC:

definput.import={'amt_cache'}; % setup the usage of cache mode flags
[flags,~]  = ltfatarghelper({},definput,varargin); % get default or user-defined cache mode
[x,y,z] = amt_cache('get', 'fileABC', flags.cachemode); % get the cached data
if isempty(x) % x is empty if cache not available or cache mode set to recalculate
      % calculate your variables x,y,z here
    amt_cache('set', 'fileABC', x, y, z); % cache calculated variables in fileABC
end
%  use your variables x, y, z here

Note that in this example, the flags indicating the mode of caching are stored in flags.cachemode. These flags can be obtained by:

definput.import={'amt_cache'};
[flags, ~] = ltfatarghelper({}, definput, varargin);

at the begin of your function. This way, the AMT's default cache mode can be overloaded by the user when calling your function.