Akavache icon indicating copy to clipboard operation
Akavache copied to clipboard

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

Open MagneticLlama opened this issue 3 months ago • 7 comments

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.

MagneticLlama avatar Sep 22 '25 21:09 MagneticLlama

Have same issue as well. Do you have any workaround @MagneticLlama ?

albilaga avatar Oct 01 '25 22:10 albilaga

Downgrading to v10 make it works again.

albilaga avatar Oct 01 '25 23:10 albilaga

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.

MagneticLlama avatar Oct 02 '25 00:10 MagneticLlama

@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);
}

MagneticLlama avatar Oct 02 '25 16:10 MagneticLlama

Same issue here. This is a deal breaker atm and blocking upgrade

Syed-RI avatar Oct 10 '25 11:10 Syed-RI

What is the status of this?

JudahSoftware avatar Oct 13 '25 14:10 JudahSoftware

Same issue here. Any news on this one? Thanks

WilliamWatterson86 avatar Oct 28 '25 13:10 WilliamWatterson86