Skip to content

[Bug]: InvalidateObject/s not working on iOS and inconsistent on Androidย #1121

@MagneticLlama

Description

@MagneticLlama

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(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions