Caching

Our system supports a semi-automatic technique to quickly save and restore data between two separate executions of vrecko.

The data are saved into the cache directory and are used if the original data haven’t changed since the creation of the cached file.

Location of the cache directory is <vreckoDIR>\vrecko\bin\cache

Automatic usage – loadGeometry()

This behaviour is fully automatic and transparent for 3D models loaded using the EnvironmentObject::loadGeometry() method.

The input model file is loaded for the first time and then immediately saved in a binary OSG format (which is very fast to load) in the cache directory. Next time the loadGeometry() method is called, the cache is checked and if the cached data matches the original file (some date & time check is performed), the cached version is loaded instead. If the loadGeometry() method detects that the original file has been modified, the cached version is automatically deleted and created again.

Manual usage in your methods

You can use the same schema for any of your data belonging to any file using the vrecko::PersistentCache class (use world->getPersistentCache() to get the pointer).

The interface is simple so you can easily save your own data. Take a look at methods VoxelGrid_Object_Data::loadFromCache() and VoxelGrid_Object_Data::saveToCache()  which employ caching of automatically calculated voxel data from a 3D model.

Class VoxelGrid_Object_Data is part of the SpacePartitioning plug-in.

The ideas

When saving data into cache, you have to present a set of 3 values.

  1. File name that you wish for this data to be associated with (file name).
  2. Name of the data (data name).
  3. Your private version number (version).

File name and data name are then used to uniquely identify the cache file.

Example

  • File name: data\MyModel.obj
  • Data name: model_statistics
  • Version: 1

The version number can be used to easily invalidate old data – if you change the code that calculates the data you can easily increment the cache version by one and the system automatically forgets the old data.

The system also automatically checks date & time of the cached file and the associated original file, compares them and reacts accordingly (it may delete the cache and return “false” to indicate that the cache is no longer accurate).