[Bug]: InvalidateObject/s not working on iOS and inconsistent on Android
Describe the bug 🐞
Calling CacheDatabase.UserAccount.InvalidateAll() on iOS or Android followed by Flush and Vacuum does not remove entries from cache. Calling CacheDatabase.UserAccount.Invalidate(key) or CacheDatabase.UserAccount.InvalidateObject<Entry>(key) followed by Flush and Vacuum does not work on iOS, but does work on Android.
Step to reproduce
Using Akavache 11.4.1
using Akavache;
using Akavache.Sqlite3;
using Akavache.SystemTextJson;
Android or iOS
var key = "entry_key"
var entry = new Entry();
await CacheDatabase.UserAccount.InsertObject(key, entry).ToTask();
await CacheDatabase.UserAccount.Flush().ToTask();
await CacheDatabase.UserAccount.InvalidateAll().ToTask();
await CacheDatabase.UserAccount.Flush().ToTask();
await CacheDatabase.UserAccount.Vacuum().ToTask();
var cachedEntry = await CacheDatabase.UserAccount.GetObject<Entry>(key).FirstOrDefaultAsync().Catch(Observable.Return<Entry>(null)).ToTask().CaptureContext();
if (cachedEntry != null)
{
throw new Exception("Found cached entry when we should have received null")
}
iOS
var key = "entry_key"
var entry = new Entry();
await CacheDatabase.UserAccount.InsertObject(key, entry).ToTask();
await CacheDatabase.UserAccount.Flush().ToTask();
await CacheDatabase.UserAccount.Invalidate(key).ToTask();
// OR
// await CacheDatabase.UserAccount.InvalidateObject<Entry>(key).ToTask();
await CacheDatabase.UserAccount.Flush().ToTask();
await CacheDatabase.UserAccount.Vacuum().ToTask();
var cachedEntry = await CacheDatabase.UserAccount.GetObject<Entry>(key).FirstOrDefaultAsync().Catch(Observable.Return<Entry>(null)).ToTask();
if (cachedEntry != null)
{
throw new Exception("Found cached entry when we should have received null")
}
Reproduction repository
No response
Expected behavior
When calling InvalidateAll the cache should be purged of all objects. When calling Invalidate or InvalidateObject on iOS, the cache should be purged of the object matching the key.
Screenshots 🖼️
No response
IDE
Visual Studio 2022
Operating system
Windows 11 / Mac OS
Version
No response
Device
iPhone, Android
ReactiveUI Version
No response
Additional information ℹ️
I'm using InvalidateAll to clear my cache on app Logout, but the data is being preserved. I've only tested UserAccount.
Have same issue as well. Do you have any workaround @MagneticLlama ?
Downgrading to v10 make it works again.
Have same issue as well. Do you have any workaround @MagneticLlama ?
I've thought about deleting the actual sqlite files, and then reinitializing Akavache from scratch, but I haven't attempted this yet.
@albilaga I have a workaround for my project that I'll use until the core issue is resolved. I haven't tested it for all cache types or EncryptedSqliteBlobCache.
public async Task Wipe()
{
await InvalidateAll(CacheDatabase.UserAccount as SqliteBlobCache).ConfigureAwait(false);
//await CacheDatabase.UserAccount.InvalidateAll().ToTask().ConfigureAwait(false);
//await CacheDatabase.UserAccount.Vacuum().ToTask().ConfigureAwait(false);
//await CacheDatabase.UserAccount.Flush().ToTask().ConfigureAwait(false);
}
private static async Task InvalidateAll(SqliteBlobCache cache)
{
if (cache?.Connection == null)
return;
await cache.Connection.RunInTransactionAsync(sql =>
{
sql.DeleteAll<CacheEntry>();
}).ConfigureAwait(false);
}
Same issue here. This is a deal breaker atm and blocking upgrade
What is the status of this?
Same issue here. Any news on this one? Thanks