Toolbox Path Caching in MATLAB
About Toolbox Path Caching in MATLAB
For performance reasons, MATLAB® disables folder change detection for the
matlabroot
folder and caches the folder information
across sessions. The disabled folder change detection and caching features are
mostly transparent to you. However, if MATLAB does not see the latest versions of your MATLAB code files or if you receive warnings about the path cache, then you
might need to update the cache.
Using the Cache File Upon Startup
Upon startup, MATLAB gets information from a cache file to build the
matlabroot
folder cache. Because of the cache file,
startup is faster, especially if you run MATLAB from a network server or if you have many folders within the
matlabroot
folder. When you end a session,
MATLAB updates the cache file.
MATLAB does not use the cache file at startup if you clear the Enable toolbox path cache check box in General Preferences page of the Preferences Window. Instead, it creates the cache by reading from the operating system folders, which is slower than using the cache file.
Updating the Cache and Cache File
How the Toolbox Path Cache Works
MATLAB caches (essentially, stores in a known files list) the names and
locations of files in the matlabroot
folder. This
folder is for files provided with MathWorks® products that should not change except for product installations
and updates. Caching those folders provides better performance during a session
because MATLAB does not actively monitor those folders.
We strongly recommend that you save any MATLAB code files you create and any files provided by MathWorks that you edit in a folder that is not in the
matlabroot
folder tree. If you keep your files in
the matlabroot
folder, then they might be overwritten
when you install a new version of MATLAB.
When to Update the Cache
When you add files to the matlabroot
folder, the
cache and the cache file need to be updated. MATLAB updates the cache and cache file automatically when you install
toolboxes or toolbox updates using the installer for MATLAB. MATLAB also updates the cache and cache file automatically when you use
MATLAB tools, such as when you save files from the MATLAB Editor to the matlabroot
folder.
When you add or remove files in the matlabroot
folder by some other means, MATLAB might not recognize those changes. For example, when you:
Save new files in the
matlabroot
folder using an external editorUse operating system features and commands to add or remove files in the
matlabroot
folder
and then attempt to use one of the new files, MATLAB displays this message:
Undefined function or variable
Update the cache so MATLAB recognizes the changes you made in the
matlabroot
folder.
Steps to Update the Cache
To update the cache and the cache file,
On the Home tab, in the Environment section, click Preferences. Select MATLAB > General.
Click Update Toolbox Path Cache and click OK.
Function Alternative
To update the cache, use rehash toolbox
. To update both the
cache and the cache file, use rehash toolboxcache
. For more
information, see rehash
.