Caching
Caching improves performance by storing data in RAM rather than directly to permanent storage. This allows you to combine multiple reads and writes into a single call, significantly improving performance when files contain many keys.
Enabling caching
You can enable caching by changing the Location to Cache in Tools > Easy Save 3 > Settings.
This will automatically load the default file (i.e. the file defined by the Default File Path in Settings) into the cache when your application starts. You can change this using the Auto cache default file setting.
It will also automatically store any dirty cached files to permanent storage at the end of every frame. You can change this using the Store cached data setting.
You can alternatively use an ES3Settings object to set the Storage Location to ES3.Location.Cache for a specific ES3 method call, but you would need to manually cache and store the file yourself as described in the sections below.
Saving to the cache
When the storage location is set to Cache, your save calls will automatically save to the cache rather than permanent storage, so the way you use ES3.Save does not change.
1 2 3 |
// Save to the cache. ES3.Save("myInt", 123); ES3.Save("myTransform", this.transform); |
Loading from the cache
When the storage location is set to Cache, your load calls will automatically load from the cache rather than permanent storage, so the way you use ES3.Load does not change.
Note that you can’t load from a file which doesn’t exist in the cache. If you have set the Location to Cache in the Settings window then Easy Save will automatically load your file into the cache.
If you are using an ES3Settings object to set the location to the Cache, or are saving to files other than the default file, you will need to use ES3.CacheFile to load the file into the cache before loading from it as described in the next section.
Manually loading a file into the cache
You can load an existing file from permanent storage into the cache using ES3.CacheFile:
1 2 3 4 5 6 7 8 9 10 |
// Cache the default file and load from it. ES3.CacheFile(); // Create an ES3Settings to load from cache. // You don't need to do this if you have the Location set to Cache in Settings. var settings = new ES3Settings(ES3.Location.Cache); // Load from the cached file. var myInt = ES3.Load("myInt", 0, settings); ES3.LoadInto("myTransform", this.transform, settings); |
The ES3.CacheFile method can also accept a filePath or an ES3Settings object if you wish to cache a specific file rather than the default file:
1 2 3 4 5 6 7 8 9 |
// Cache MyFile.es3 and load from it. ES3.CacheFile("MyFile.es3"); // Create an ES3Settings to load from cache. var settings = new ES3Settings("MyFile.es3", ES3.Location.Cache); // Load from the cached file. var myInt = ES3.Load("myInt", 0, settings); ES3.LoadInto("myTransform", this.transform, settings); |
Manually storing a cached file to a local file
You might need to manually tell Easy Save to store a file in the Cache to permanent storage, for example if you are using an ES3Settings object to enable caching rather than setting it in the default settings.
You can do this using ES3.StoreCachedFile.
1 2 3 4 5 6 7 8 9 |
// Make multiple save calls to the cache. ES3.Save("myInt", 123, settings); ES3.Save("myTransform", this.transform, settings); // Store the default cached file to a permanent local file. ES3.StoreCachedFile(); // You can also store a specific file to the cache. ES3.StoreCachedFile("MyFile.es3"); |