Io.open getting stale data on HTML5

This is not exactly a bug maybe because I’m not using it as intended… but when I use io.open repeatedly to read from a file within the indexeddb object store on HTML5 builds I am noticing that it only correctly reads the set content the first time, and then after that it seems to pull from a cache instead. Is there a way I get Defold to use the actual indexeddb data? Attached is a sample. I made a number of incorrect assumptions in it working before, and I don’t have enough extra time right now to understand why and how to get it to work. I understand that these are not direct Defold features, but of emscripten. The goal is to enable a method to communicate within HTML5 builds between Defold and its html container. The communication works, but Defold’s side uses stale data. Help?

html5_inbox.zip (17.7 KB)

Ah, yes, the data is cached in some way and at some interval flushed to disk. @sven knows more.

A token to force reading from “disk” once, the next read, or constantly would be enough. I didn’t test this specifically, but I think it does save to “disk” each time. It would be worth testing / checking to make sure there is less chance of data loss if it only saves to the virtual file system most of the time.

The JS code that is bundled with the default HTML template, synchronises data from the IDB to memory at start, then syncs from memory to IDB after each file close. This means that there will not be any automatic IDB->memory syncs after the initial one.

But this is maybe something you could trigger yourself, check out FS.syncfs() in the emscripten documentation. As previously stated, we call this essentially after each file close, with the first parameter set to false (this syncing from IDB->memory).

And as you pointed out, you are using the underlaying filesystem functionality in ways not intended (by Defold at least), so you are doing this at your own “risk”. But it sounds fun, let us know how it goes! :wink:

5 Likes

Thank you for the insights, Sven!

I’ll do more tests soon.

2 Likes