Akavache icon indicating copy to clipboard operation
Akavache copied to clipboard

App Data Size

Open meenanarendra opened this issue 8 years ago • 6 comments

Note: for support questions, please ask on StackOverflow: https://stackoverflow.com/questions/tagged/Akavache . This repository's issues are reserved for feature requests and bug reports.

Do you want to request a feature or report a bug? Bug

What is the current behavior?

I'm using Akavache for my Android app and I'm seeing an issue where the app storage keeps growing even after deleting all items from the cache. I'm seeing the increase by going to App Info and looking at the Data total under Storage.

Looking through adb, I see the sqlite3-wal file growing in size, while the sqlite3 file is unchanged.

I'm calling the following to clear the cache:

public void DeleteAll() { // _cache is an instantiated SQLitePersistentBlobCache instance _cache.InvalidateAll().ToTask().Wait(); _cache.Vacuum().ToTask().Wait(); } That method properly invalidates my cache and causes data to be downloaded again, but how can I ensure the app's storage will decrease when the Akavache cache is cleared?

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

What is the expected behavior?

Should reduce the file zie to zero on cleanup

What is the motivation / use case for changing the behavior?

To save memory size

Which versions of Akavache, and which platform / OS are affected by this issue? Did this work in previous versions of Akavache? Please also test with the latest stable and snapshot (https://www.myget.org/feed/Akavache/package/nuget/Akavache) versions. Android - 5.0.0 version

Other information (e.g. stacktraces, related issues, suggestions how to fix)

meenanarendra avatar Mar 20 '18 21:03 meenanarendra

Any comments on this? I'm experiencing the same issue on iOS.

YuliaLoyko avatar Jun 29 '18 10:06 YuliaLoyko

Did you try latest 6 version? do you see this problem?

EmilAlipiev avatar Oct 16 '18 11:10 EmilAlipiev

Hi, I also got this problem and I use the latest version of Akavache. Could anyone have any updates from it?

khongta0932488598 avatar Jul 30 '19 02:07 khongta0932488598

Any update on this?

rhy-ama avatar Nov 01 '19 16:11 rhy-ama

In the year 2022, I can reproduce this issue.

image

db-wal grows infinitely until Sqlite performs an automatic checkpoint; but the checkpoint threshold is too high if you are storing binary blobs. Closing the DB file is not flushing and deleting wal file (it should!); and I do not think SQLITE_FCNTL_PERSIST_WAL is set either.

In any case, calling Vacuum() is ironically causing the large increase in storage use, as the WAL is never flushed to main file.

Manually VACUUM'ing closing connection

var connection = _cache.Connection;
connection.Execute("VACUUM", Array.Empty<object>());
connection.Close();
connection.Dispose();

has no effect either. Which makes me believe it's not Akavache specific, but specific to the underlying SQLite provider. I haven't had a good enough look.

image


Edit: You can work around this by explicitly flushing WAL on shutdown.

_cache.Flush().Wait();
_cache.Vacuum().Wait();
_cache.Connection.ExecuteScalar<int>("PRAGMA wal_checkpoint(TRUNCATE)", Array.Empty<object>());
_cache.Dispose();
_cache.Shutdown.Wait();

This should shrink the WAL file to 0 bytes. Alternatively, disable WAL mode on shutdown which should cause the WAL to be flushed to main file and deleted.

_cache.Connection.Execute("PRAGMA journal_mode = DELETE", Array.Empty<object>());

Both work for me.

Sewer56 avatar Aug 03 '22 00:08 Sewer56

This is Odd, as @Sewer56 mentioned, closing the database should cause the WAL file to be cleaned up, I wonder if something is being leaked

anaisbetts avatar Aug 03 '22 10:08 anaisbetts