Cache Questions

Discussion and help for Easy Save 3
Post Reply
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Cache Questions

Post by mikemnd »

I'm dealing with a similar thing and the docs are not super helpful.

So as i looked trough the source code and what i saw from test is that:

1. If you create a settings with:

Code: Select all

Settings = new ES3Settings(ES3.Location.Cache);
And than whenever you want to use the Cache you should pass the Settings variable as parameter.
Another option is to set it in the UI as default value (or as default setting in the code runtime).

2. This wont create any files on the file system so to write the cache file to system you should call:

ES3.StoreCachedFile(Settings); // here I have some questions too

This works but some times there is an error that if this is called before a Cache file is created so I've added the check:

Code: Select all

if (ES3.FileExists(Settings))
{
    ES3.StoreCachedFile(Settings);
}
StoreCachedFile method also can receive 1st parameter path so you could change it in your case to "Slot1.es3", "Slot2.es3" or "Slot3.es3"

3. So with step 1 and 2 you should have a ES3 cache saving and occasionally when you call the StoreCachedFile you will have a file on the file system. Later on when you want to load the save as the guide points you should call:

Code: Select all

 ES3.CacheFile();


Here you should pass again the Settings or give the path and Settings... and also this is one of the points where I'm not 100% what is the right way.

Together with the question above I have a case where the user could delete the save game... and till now I don't have succes with deleting
the persistent file and the cache...

I'm using

Code: Select all

if (ES3.FileExists(Settings))
{
    ES3.DeleteFile(Settings);
}
So this is my experience from today, sorry if I've made some mistakes but I hope Joel will clear out and expand more on the guide for the saving with Cache.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Cache Questions

Post by Joel »

Hi there,

I've moved your post to a new thread to avoid confusion, as your questions were different to those asked by the poster of the thread you posted in.

ES3.StoreCachedFile accepts a filePath parameter. So if you save data to the cache using:

Code: Select all

ES3.Save("myKey", myValue, "myFileName.es3");
You can store that cached file using:

Code: Select all

ES3.StoreCachedFile("myFileName.es3");
Regarding deleting data, if you have Cache set as your storage location then it will only delete the data from the cache, not from the hard disk. If you also want to delete data from storage, you will need to set the save location to File.

i.e.

Code: Select all

// Delete from cache
var cacheSettings = new ES3Settings(ES3.Location.Cache);
ES3.DeleteFile("myFileName.es3", cacheSettings);

// Delete from hard disk
var fileSettings = new ES3Settings(ES3.Location.File);
ES3.DeleteFile("myFileName.es3", fileSettings);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Re: Cache Questions

Post by mikemnd »

Hi Joel,
Double deleting makes sense now.
Thanks.
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Re: Cache Questions

Post by mikemnd »

Just saw something that may need fixing:

Code: Select all

    /// <summary>Stores a cached file to persistent storage.</summary>
    /// <param name="settings">The settings of the file we want to store to.</param>
    public static void StoreCachedFile(ES3Settings settings)
    {
        ES3File.Store(settings);
    }

Code: Select all

    /// <summary>Stores a cached file to persistent storage.</summary>
    /// <param name="filePath">The filename or path of the file we want to store the cached file to.</param>
    public static void CacheFile(string filePath)
    {
        CacheFile(new ES3Settings(filePath));
    }
The doc bloc says the same:
Stores a cached file to persistent storage.
but one is to store cached file to persistent and the other is to load a persistent file into cache (store file to cache)
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Cache Questions

Post by Joel »

Well spotted, looks like we forgot to change the summary. I'll ensure this is resolved in the next update.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply