cacheFile( fname )

The cacheFile function is an updateable function, which means you can use the function application on the left hand side of an assignment.

For the purporses of this description it's actually easier to start with the most complicated use of this function! The rationale here is that the simpler use is to just apply the function, e.g. to load a cache file, but that requires that we already have a cache file. Hence, we have to learn how to create a cache file first...

To create a cache file, we put the cacheFile function application on the left hand side of an assignment, while we put the contents for the cache file on the right hand side. e.g.

:-) cacheFile( "somefile" ) := "a test string";
There are 0 results
      

The above example creates a cache file called somefile, which contains the string "a test string". The cache file contents are actually serialised Java objects, so you can put any valid MillScript object into a cache file.

To read a cache file, we simply put the cacheFile function application anywhere but the left hand side of an assignment, e.g.

:-) cacheFile( "somefile" );
There is 1 result
"a test string"
      

cacheFile( fname, default )

The two argument version of the cache file function gives you a limited ability to handle errors when loading a cache file.

The additional argument allows you to specify a default value to use if there is a problem loading the specified cache file. e.g. if the cache file doesn't exist, or the cache file is corrupted, the value of the default argument will be returned. If a value in the cache cannot be loaded for other reasons a mishap will still be generated.

NOTE - The two argument version of the cache file function is not an updateable function.