An asynchronous, persistent key-value store created for writing desktop and mobile applications, based on SQLite3. Akavache is great for both storing important
An asynchronous, persistent key-value store created for writing desktop and mobile applications, based on SQLite3. Akavache is great for both storing important
Akavache is an asynchronous, persistent (i.e., writes to disk) key-value store created for writing desktop and mobile applications in C#, based on SQLite3. Akavache is great for both storing important data (i.e., user settings) as well as cached local data that expires.
Akavache V12 rewrites the SQLite backend for direct SQLitePCLRaw 3.x access, replacing the sqlite-net-pcl ORM layer entirely. The result is lower per-operation allocations, dedicated worker-thread serialization of all native handle access, and commit coalescing for concurrent writes.
SettingsBase properties are IObservable<T> — no more .Wait() deadlocksJsonTypeInfo<T> overloads for System.Text.Json, trim-safe out of the boxInterlocked patterns for idempotent disposeSee the Migration Guide: V11 to V12 for upgrade instructions.
<PackageReference Include="Akavache.Sqlite3" Version="*" />
<PackageReference Include="Akavache.SystemTextJson" Version="*" />
Note:
WithAkavache,WithAkavacheCacheDatabaseandInitializealways requires anISerializerdefined as a generic type, such asWithAkavache<SystemJsonSerializer>. This ensures the cache instance is properly configured for serialization.
using Akavache.Core;
using Akavache.SystemTextJson;
using Akavache.Sqlite3;
using Splat.Builder;
// Initialize with the builder pattern
AppBuilder.CreateSplatBuilder()
.WithAkavacheCacheDatabase<SystemJsonSerializer>(builder =>
builder.WithSqliteProvider() // REQUIRED: Explicitly initialize SQLite provider
.WithSqliteDefaults(),
"MyApp");
Important: Always call
WithSqliteProvider()explicitly beforeWithSqliteDefaults(). WhileWithSqliteDefaults()will automatically callWithSqliteProvider()if not already initialized (for backward compatibility), this automatic behavior is deprecated and may be removed in future versions. Explicit provider initialization is the recommended pattern for forward compatibility with other DI containers.
…
// Store an object
var user = new User { Name = "John", Email = "[email protected]" };
await CacheDatabase.UserAccount.InsertObject("current_user", user);
// Retrieve an object
var cachedUser = await CacheDatabase.UserAccount.GetObject<User>("current_user");
// Store with expiration
await CacheDatabase.LocalMachine.InsertObject("temp_data", someData, DateTimeOffset.Now.AddHours(1));
// Get or fetch pattern
var data = await CacheDatabase.LocalMachine.GetOrFetchObject("api_data",
async () => await httpClient.GetFromJsonAsync<ApiResponse>("https://api.example.com/data"));
Akavache provides four types of caches:
// User preferences (persistent)
await CacheDatabase.UserAccount.InsertObject("user_settings", settings);
// API cache (temporary)
await CacheDatabase.LocalMachine.InsertObject("api_cache", apiData, DateTimeOffset.Now.AddHours(6));
// Sensitive data (encrypted)
await CacheDatabase.Secure.SaveLogin("john.doe", "secretPassword", "myapp.com");
// Session data (in-memory only)
await CacheDatabase.InMemory.InsertObject("current_session", sessionData);
Install the packages that match your needs. At minimum you need the core package plus a storage backend and a serializer.
| Purpose | Package | NuGet |
|---|---|---|
| Core (in-memory cache) | Akavache | |
| SQLite persistence | Akavache.Sqlite3 | |
| Encrypted SQLite persistence | Akavache.EncryptedSqlite3 | |
| System.Text.Json serializer (recommended) | Akavache.SystemTextJson | |
| System.Text.Json BSON serializer | Akavache.SystemTextJson.Bson | |
| Newtonsoft.Json serializer | Akavache.NewtonsoftJson | |
| HTTP download and caching extensions | Akavache.HttpDownloader | |
| Image/bitmap caching | Akavache.Drawing | |
| Application settings helpers | Akavache.Settings | |
| V10 → V11 data migration | Akavache.V10toV11 |
Akavache uses a modular package structure. Choose the packages that match your needs:
<PackageReference Include="Akavache" Version="*" />
<PackageReference Include="Akavache.Sqlite3" Version="*" />
<PackageReference Include="Akavache.EncryptedSqlite3" Version="*" />
<PackageReference Include="Akavache.SystemTextJson" Version="*" />
<PackageReference Include="Akavache.NewtonsoftJson" Version="*" />
<PackageReference Include="Akavache.HttpDownloader" Version="*" />
<PackageReference Include="Akavache.Drawing" Version="*" />
<PackageReference Include="Akavache.Settings" Version="*" />
Akavache supports:
net9.0-android, net9.0-ios, net9.0-maccatalyst, net10.0-android, net10.0-ios, net10.0-maccatalystnet9.0-windows10.0.19041.0, net10.0-windows10.0.19041.0 (WinUI), net9.0, net10.0 (cross-platform)| Serializer | .NET Framework 4.6.2+ | .NET 8.0+ | Mobile | Performance |
|---|---|---|---|---|
| System.Text.Json | ✅ Via NuGet | ✅ | ✅ | Fastest |
| Newtonsoft.Json | ✅ Built-in | ✅ | ✅ | Compatible |
Recommendation: Use System.Text.Json for new projects for best performance. Use Newtonsoft.Json when migrating from older Akavache versions or when you need maximum compatibility.
Akavache.Settings provides a specialized settings database for application configuration that survives app updates and reinstalls.
…
Settings are automatically persisted and will survive app updates, making them perfect for user preferences and application configuration.
Complete documentation is available in the /docs folder:
This project is tested with BrowserStack.
We want to thank the following contributors and libraries that help make Akavache possible:
No open issues yet, or sync has not completed.