Describe the bug
cacheVersion is not written to the journal correctly. An identical setup with just the cacheVersion variable changed on a FileCache and starting out from no cache saved at all, will yield two wildly different outcomes. When the version is set to one, it works perfectly. However, if it is anything but 1, each time the cache is initialized it will reset. This is because the version is not written to the journal but is indeed checked correctly on loading. Since the default version is 1 it works fine but if it is anything but 1 the cache will be reset on startup, which is intended, but since the version is not written this happens each time.
To Reproduce
Steps to reproduce the behavior:
- Have a
FileCache with a version of anything other than 1
- After the cache is initialized, add an item to it (observe it is saved properly and everything seems to be working fine)
- Close and reopen the cache (observe it is cleared)
Expected behavior
The version number should be written to the journal and therefore checked correctly.
System (please complete the following information):
- Device: Google Pixel 8
- OS: Android 16
Additional context
I spent multiple hours tracking down the issue, since I thought it was my fault but, for once, it wasn't :). It comes down to the writing of the header in the journal file: the JournalWriter has a parameter called cacheVersion, which is never explicitly set and therefore always has the default value of 1. It should be a matter of setting this parameter on creation of the writer to the wanted value. This would need to happen in the following places:
- When the
OkioFileKache is opened
- When the journal is rebuilt
- Technically it should also be set when the JournalWriter is created in the
OkioFileKache and used for entries, but since the header is not written in these cases it could be skipped
Describe the bug
cacheVersionis not written to the journal correctly. An identical setup with just thecacheVersionvariable changed on aFileCacheand starting out from no cache saved at all, will yield two wildly different outcomes. When the version is set to one, it works perfectly. However, if it is anything but1, each time the cache is initialized it will reset. This is because the version is not written to the journal but is indeed checked correctly on loading. Since the default version is1it works fine but if it is anything but1the cache will be reset on startup, which is intended, but since the version is not written this happens each time.To Reproduce
Steps to reproduce the behavior:
FileCachewith a version of anything other than1Expected behavior
The version number should be written to the journal and therefore checked correctly.
System (please complete the following information):
Additional context
I spent multiple hours tracking down the issue, since I thought it was my fault but, for once, it wasn't :). It comes down to the writing of the header in the journal file: the
JournalWriterhas a parameter calledcacheVersion, which is never explicitly set and therefore always has the default value of1. It should be a matter of setting this parameter on creation of the writer to the wanted value. This would need to happen in the following places:OkioFileKacheis openedOkioFileKacheand used for entries, but since the header is not written in these cases it could be skipped