function whdlexamplesCopyCacheFiles(modelNames)
    %whdlexamplesCopyCacheFiles copy simulink cache files for the current mex
    %configuration to the simulink cache directory, if they exist.
    
    cacheLeafFolder = Simulink.ModelReference.getSLXCCacheLeafFolder();
    
    cfg = Simulink.fileGenControl('getConfig');
    cacheFolder = cfg.CacheFolder;

    if ~isempty(cacheLeafFolder)
        for k = 1:length(modelNames)
            % copy the cache files into example's Work folder
            source = fullfile(matlabroot, 'toolbox', 'whdl', 'whdlexamples', ...
                                  'modelRefCache', ...
                                  cacheLeafFolder, ...
                                  [modelNames{k} '.slxc']);
            target = fullfile(cacheFolder,[modelNames{k} '.slxc']);
            
            if exist(source,'file')
                %only attempt to copy up if the slxc file exists - this
                %depends on whether a prexisting slxc has been built for
                %the target configuration
                matlab.internal.examples.copyIfMissing(source,target);
            end
        end
    end
end