could not be stored because it could not be found in the cache.

Discussion and help for Easy Save 3
Post Reply
sbmhome
Posts: 9
Joined: Thu Oct 29, 2020 9:24 pm

could not be stored because it could not be found in the cache.

Post by sbmhome »

I recently implemented using the CacheFile to make game saves more performant.

I noticed that when I execute ES3.StoreCachedFile () I get the below error message.


FileNotFoundException: The file 'GameSave1.txt' could not be stored because it could not be found in the cache.
ES3File.Store (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:388)
ES3.StoreCachedFile () (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:1385)



Notes:
1. I have a key thats called "GameSave1.txt" and the game save file has the same name "GameSave1.txt"....would this be a problem? It wasn't before I implemented the Cache. Just want to make sure that this is not the issue.

2. Also when I hover over ES3.CacheFile() or ES3.StoreCachedFile () in Visual Studio, they both say "Stores the default cache file to persistent Storage", but in the docs is says to use ES3.CacheFile() to load the file....that's what I've been doing...just wanted to verify this.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: could not be stored because it could not be found in the cache.

Post by Joel »

Hi there,

Regarding your first point, that shouldn’t be an issue.

ES3.CacheFile loads a file from persistent storage into the cache. ES3.StoreCachedFile saves a cached file back to persistent storage.

Please could you show me the code you’re using so that I can understand what is happening?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sbmhome
Posts: 9
Joined: Thu Oct 29, 2020 9:24 pm

Re: could not be stored because it could not be found in the cache.

Post by sbmhome »

Ok, after doing some more digging it looks like using Encryption is causing some issues. When I don't use encryption, everything works fine and I get no errors, once I turn it on I get the error message that posted AND I get the below error message. Is it possible that the format for the cachedFile and the file are not in sync as far as encryption is concerned? As I said, this only happens with encryption on.

I'm using

GameSettings.Instance.gameSaveFile = "GameSave1.txt"


public class GameSave {
public int locationReachedIndex = 0;
public float hitpoints = 100;
public int filaments;
public int playerCarriedFilaments;
}

gameSave = new GameSave();


To Cache the File in Memory
ES3.CacheFile(GameSettings.Instance.gameSaveFile);

To Save Data to Cache
var eC3CacheFile = new ES3Settings(ES3.Location.Cache);
ES3.Save(GameSettings.Instance.gameSaveFile, gameSave, eC3CacheFile);



Notes:
1. I delete the save file before I try running the game as I know it cant read a file if its encrypted and encryption if Off...and vice versa.



ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
ES3Internal.ES3Stream.CreateStream (System.IO.Stream stream, ES3Settings settings, ES3Internal.ES3FileMode fileMode) (at Assets/Plugins/Easy Save 3/Scripts/Streams/ES3Stream.cs:102)
ES3Reader.Create (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:364)
ES3File.SaveRaw (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:170)
ES3File..ctor (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:83)
ES3File.CacheFile (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:371)
ES3.CacheFile (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:1437)
ES3.CacheFile (System.String filePath) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:1422)
SceneLoadComplete+<LoadCacheFile>d__36.MoveNext () (at Assets/Main/Scripts/SceneControllers/SceneLoadComplete.cs:286)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: could not be stored because it could not be found in the cache.

Post by Joel »

Hi there,

Please could you show me the code you're using to create the file you're caching?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sbmhome
Posts: 9
Joined: Thu Oct 29, 2020 9:24 pm

Re: could not be stored because it could not be found in the cache.

Post by sbmhome »

Ok, I'm confused. I thought I mentioned it in the first post.

To store the cached file to disk.
ES3.StoreCachedFile();

Here is the line of code for save to Cache
ES3.Save(GameSettings.Instance.gameSaveFile, gameSave, eC3CacheFile);

Here is the line of code for save to Disk (This get called BEFORE I use the cache.... to create the file)
ES3.Save(GameSettings.Instance.gameSaveFile, gameSave, GameSettings.Instance.gameSaveFile);

Is that the info you need?
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: could not be stored because it could not be found in the cache.

Post by Joel »

Hi there,

Apologies, I missed that line.

There appears to be an error in your code. The first parameter to the ES3.Save method is a key to uniquely identify the data, but you appear to be providing the filePath for this parameter. For the filename you appear to be providing the eC3CacheFile variable, which isn't the variable you're specifying as the filePath when using the cache methods.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sbmhome
Posts: 9
Joined: Thu Oct 29, 2020 9:24 pm

Re: could not be stored because it could not be found in the cache.

Post by sbmhome »

I must have a fundamental misunderstanding on how the caching works.

Should I be loading the cache from the Disk file? Or should I be creating a new file in the cache, then saving it to disk afterwards?

Currently I'm try to load the cache from disk by doing this.


//Create gameSave
ES3.Save(GameSettings.Instance.gameSavePlayerData, gameSave, GameSettings.Instance.gameSaveFile);

//Load GameSave from Disk INTO the cache
ES3.CacheFile(GameSettings.Instance.gameSaveFile);

it is here that I'm getting an error
ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
ES3Internal.ES3Stream.CreateStream (System.IO.Stream stream, ES3Settings settings, ES3Internal.ES3FileMode fileMode) (at Assets/Plugins/Easy Save 3/Scripts/Streams/ES3Stream.cs:102)


Should I instead make a new Cache file by doing this instead?
//Create gameSave
ES3.Save(GameSettings.Instance.gameSavePlayerData, gameSave, GameSettings.Instance.gameSaveFile);

//Create New Cache
GameSettings.Instance.gameSaveCache
ES3.CacheFile(GameSettings.Instance.gameSaveCache);
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: could not be stored because it could not be found in the cache.

Post by Joel »

Hi there,

Please could you create a new script which I can drop into a new scene which replicates your issue? I still don't seem to be able to replicate this.

Also just to check, are you using the latest version of Easy Save?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
sbmhome
Posts: 9
Joined: Thu Oct 29, 2020 9:24 pm

Re: could not be stored because it could not be found in the cache.

Post by sbmhome »

First thanks for the quick responses...much appreciated.

I think I may have just found the issue. As it seems to working correctly now.

It looks like the Cache file must be a different name from the actual disk file, I thought they had to be the same.

I thought this because I thought the cache needed to be loaded from disk before I used it.


In any case, this seemed to causing both error messages.

The first error because it was confused by encryption of the disk file and the second happened because the first operation failed.

Again, thanks for the help!
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: could not be stored because it could not be found in the cache.

Post by Joel »

Hi there,

Just to clarify, the filename you save to needs to be the same as the file you cache. I've had no reports of this being otherwise.

If you're able to replicate this in a new, empty project with a very simple scene and private message it to me then I'm happy to take a further look.

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