Best Practice and Limitations of cache

Discussion and help for Easy Save 3
Post Reply
iVale
Posts: 2
Joined: Tue Jun 08, 2021 2:03 am

Best Practice and Limitations of cache

Post by iVale »

First of all, love this asset. I just have some very basic questions on best practice and limitations.

I'm not a particularly efficient coder and I tend to jerry rig a lot of my code to just work. I've combed the documentation and the forums and I've rigged up a multi slot save system that works, but I have a feeling it's going to give me some issues further down the line. I use ES3.Save and ES3.Load calls on persistent objects on the awake and destroy, like bools on items and the vector3's of enemies added to the file with a generated GUID, saving to my persistentData.es3 in the cache. So in my head, the further into the game you get, the bigger the cache files going to get with bools etc..

This is where things get weird. To Save and Load the game, I have a save and load UI with buttons that represent slots. When you save, it makes a copy of my persistentData.es3 to a saveSlot#.es3 using ES3.CopyFile in the cache, saves that locally with the ES3.StoreCachedFile(saveSlot#), then deletes the saveSlot file in the cache. When loading the game, it loads the local saveSlot file into the cache, copies it overtop of the persistentData.es3, and deletes the save slot in the cache. Essentially syncing up my persistentData.es3 with a local save file.

So this works. But I notice nobody seems to be doing things this way, so i'm curious if theres a glaring downside that I'm just not seeing, and if it's going to give me some issues further down the line. Is it expensive to make ES3.Load calls from the cache file? Whats stopping me from using ES3.Load for all my random persistent data, like currentHealth variables, or ammo counts?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Best Practice and Limitations of cache

Post by Joel »

Hi there,

It would be hard to say what is right for your particular project, but I don't see anything wrong with the way you're doing things. It's usually better to do things in a more understandable but less efficient way than a less understandable but more efficient way.

ES3.Load calls from cache are extremely inexpensive (it's essentially a dictionary lookup for primitive types, and a dictionary lookup and deserialize for other objects), especially compared to loading directly from file.

The biggest expense is File IO, but using caching ensures that you only need one IO call for saving the data, and one for loading it (as opposed to one for each piece of data you save).

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
iVale
Posts: 2
Joined: Tue Jun 08, 2021 2:03 am

Re: Best Practice and Limitations of cache

Post by iVale »

Thank you for the prompt reply! I really appreciate it.
Post Reply