cachedcall

버전 1.5.0.0 (8.61 KB) 작성자: Aslak Grinsted
Cache the results of slow function calls
다운로드 수: 610
업데이트 날짜: 2015/3/30

라이선스 보기

편집자 메모: This file was selected as MATLAB Central Pick of the Week

CACHEDCALL can be used to cache the results of slow function calls to disk

You can call an arbitrary function using cachedcall. It will then check
if you have made the same call with the same arguments before. If you
have then it will quickly load the previously computed results from the
disk cache rather than calculating them again. If there are no matching
calls in the cache, then the results will be calculated and saved in the
cache.

USAGE: [a,b,...]=cachedcall(fun[,Arguments,parameter,value])

INPUTS:
fun: handle to function whose outputs should be cached.
arguments: a cell with all the arguments that should be passed to fun.

Optional Named Parameters:
CacheFolder: the folder where the results are cached. The default folder
is the system temporary files folder (see tempdir)
MaxCacheSize: The maximum size of the cache before oldest cached
results will be deleted. (default=3e9)
SaveArguments: (default=false) this can be used to also save the input
arguments passed to the function in the cache
MaxAge: discards cache if older than maxage - units are days.
(default=inf)
Tag: A custom string that can be saved in the cache. displayed
when inspecting (default a string describing contents of Arguments)

Further usage:
* cachedcall clear - will empty the entire cache directory.
* cachedcall inspect - will inspect the contents of the cache.
* cachedcall clean - will delete expired contents of the cache.
Expired means older than MaxAge or the results
of a function that has changed

Example 1:
x=1e14+(1:50);
tic,isp1=isprime(x); normalcalltime=toc
tic,isp2=cachedcall(@isprime,x); firstcachedcalltime=toc
tic,isp3=cachedcall(@isprime,x); secondcachedcalltime=toc

Example 2: cache the results of retrieving data from the web
tic
cachedcall(@urlread,'https://www.mathworks.com/moler/ncm/longley.dat')
toc


Relies on: DataHash by Jan Simon (included in download).
Improved performance if TypeCastX by James Tursa installed (not required).

Aslak Grinsted 2015

인용 양식

Aslak Grinsted (2024). cachedcall (https://www.mathworks.com/matlabcentral/fileexchange/49949-cachedcall), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2012b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Deployable Archive Creation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.5.0.0

Updated to include newest version of DataHash

1.4.0.0

Introduced maxage parameter

1.3.0.0

wrote a better explanation of what it does.

1.2.0.0

improved description / improved nargout handling / changed datahash to include filedate & filesize in the hash of function_handles.

1.1.0.0

* Improved inspect command with links
* implemented nargout==-1 workaround for some inline functions.

1.0.0.0