Akavache - akavache 5.1.0-alpha0008

An asynchronous, persistent key-value store for desktop and mobile applications on .NET

PM> Install-Package akavache -Version 5.1.0-alpha0008 -Source https://www.myget.org/F/Akavache/api/v3/index.json

Copy to clipboard

> nuget.exe install akavache -Version 5.1.0-alpha0008 -Source https://www.myget.org/F/Akavache/api/v3/index.json

Copy to clipboard

> dotnet add package akavache --version 5.1.0-alpha0008 --source https://www.myget.org/F/Akavache/api/v3/index.json

Copy to clipboard
<PackageReference Include="akavache" Version="5.1.0-alpha0008" />
Copy to clipboard
source https://www.myget.org/F/Akavache/api/v3/index.json

nuget akavache  ~> 5.1.0-alpha0008
Copy to clipboard

> choco install akavache --version 5.1.0-alpha0008 --source https://www.myget.org/F/Akavache/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "Akavache" -SourceLocation "https://www.myget.org/F/Akavache/api/v2"
Install-Module -Name "akavache" -RequiredVersion "5.1.0-alpha0008" -Repository "Akavache" -AllowPreRelease
Copy to clipboard

NuGet Stats Build Code Coverage

Akavache

Akavache: An Asynchronous Key-Value Store for Native Applications

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.

What's New

Akavache V11.1 introduced a new Builder Pattern for initialization, improved serialization support, and enhanced cross-serializer compatibility:

  • ๐Ÿ—๏ธ Builder Pattern: New fluent API for configuring cache instances
  • ๐Ÿ”„ Multiple Serializer Support: Choose between System.Text.Json, Newtonsoft.Json, each with a BSON variant
  • ๐Ÿ”— Cross-Serializer Compatibility: Read data written by different serializers
  • ๐Ÿงฉ Modular Design: Install only the packages you need
  • ๐Ÿ“ฑ Enhanced .NET MAUI Support: First-class support for .NET 9 cross-platform development
  • ๐Ÿ”’ Improved Security: Better encrypted cache implementation

Development History

Akavache V11.1+ represents a significant evolution in the library's architecture, developed through extensive testing and community feedback in our incubator project. The new features and improvements in V11.1 were first prototyped and battle-tested in the ReactiveMarbles.CacheDatabase repository, which served as an experimental ground for exploring new caching concepts and architectural patterns.

Key Development Milestones:

  • ๐Ÿงช Incubation Phase: The builder pattern, modular serialization system, and enhanced API were first developed and tested in ReactiveMarbles.CacheDatabase
  • ๐Ÿ”ฌ Community Testing: Early adopters and contributors provided valuable feedback on the new architecture through real-world usage scenarios
  • ๐Ÿš€ Production Validation: The incubator project allowed us to validate performance improvements, API ergonomics, and cross-platform compatibility before integrating into Akavache
  • ๐Ÿ“ˆ Iterative Refinement: Multiple iterations based on community feedback helped shape the final V11.1 API design and feature set

This careful incubation process ensured that V11.1 delivers not just new features, but a more robust, flexible, and maintainable caching solution that builds upon years of community experience and testing.

Quick Start

1. Install Packages

<PackageReference Include="Akavache.Sqlite3" Version="*" />
<PackageReference Include="Akavache.SystemTextJson" Version="*" />

2. Initialize Akavache

Note: WithAkavache, WithAkavacheCacheDatabase and Initialize always requires an ISerializer defined as a generic type, such as WithAkavache<SystemJsonSerializer>. This ensures the cache instance is properly configured for serialization.

Static Initialization (Recommended for most apps)

using Akavache.Core;
using Akavache.SystemTextJson;
using Akavache.Sqlite3;
using Splat.Builder;

// Initialize with the builder pattern
AppBuilder.CreateSplatBuilder()
    .WithAkavacheCacheDatabase<SystemJsonSerializer>(builder =>
        builder.WithApplicationName("MyApp")
               .WithSqliteProvider() // REQUIRED: Explicitly initialize SQLite provider
               .WithSqliteDefaults());

Important: Always call WithSqliteProvider() explicitly before WithSqliteDefaults(). While WithSqliteDefaults() will automatically call WithSqliteProvider() 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.

Dependency Injection Registration (for DI containers)

using Akavache.Core;
using Akavache.SystemTextJson;
using Akavache.Sqlite3;
using Splat.Builder;

// Example: Register Akavache with Splat DI
AppBuilder.CreateSplatBuilder()
    .WithAkavache<SystemJsonSerializer>(
        "MyApp",
        builder => builder.WithSqliteProvider()    // REQUIRED: Explicit provider initialization
                          .WithSqliteDefaults(),
        (splat, instance) => splat.RegisterLazySingleton(() => instance));

// For in-memory cache (testing or lightweight scenarios):
AppBuilder.CreateSplatBuilder()
    .WithAkavache<SystemJsonSerializer>(
        "Akavache",
        builder => builder.WithInMemoryDefaults(),  // No provider needed for in-memory
        (splat, instance) => splat.RegisterLazySingleton(() => instance));

3. Use the Cache

Basic Operations

// Store an object
var user = new User { Name = "John", Email = "john@example.com" };
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"));

Cache Types

Akavache provides four types of caches:

  • UserAccount: User settings and preferences that should persist and potentially sync
  • LocalMachine: Cached data that can be safely deleted by the system
  • Secure: Encrypted storage for sensitive data like credentials and API keys
  • InMemory: Temporary storage that doesn't persist between app sessions
// 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);

Installation

Akavache uses a modular package structure. Choose the packages that match your needs:

Core Package (In Memory only)

<PackageReference Include="Akavache" Version="*" />

Storage Backends (Choose One - Recommended)

<!-- SQLite persistence (most common) -->
<PackageReference Include="Akavache.Sqlite3" Version="*" />

<!-- Encrypted SQLite persistence -->
<PackageReference Include="Akavache.EncryptedSqlite3" Version="*" />

Serializers (Choose One - Required)

<!-- System.Text.Json (fastest, .NET native) -->
<PackageReference Include="Akavache.SystemTextJson" Version="*" />

<!-- Newtonsoft.Json (most compatible) -->
<PackageReference Include="Akavache.NewtonsoftJson" Version="*" />

Optional Extensions

<!-- Image/Bitmap support -->
<PackageReference Include="Akavache.Drawing" Version="*" />

<!-- Settings helpers -->
<PackageReference Include="Akavache.Settings" Version="*" />

Framework Support

Akavache supports:

  • โœ… .NET Framework 4.6.2/4.7.2 - Windows desktop applications
  • โœ… .NET Standard 2.0 - Cross-platform libraries
  • โœ… .NET 8.0 - Modern .NET applications
  • โœ… .NET 9.0 - Latest .NET applications
  • โœ… .NET 10.0 - Latest .NET applications
  • โœ… Mobile Targets - net9.0-android, net9.0-ios, net9.0-maccatalyst, net10.0-android, net10.0-ios, net10.0-maccatalyst
  • โœ… Desktop Targets - net9.0-windows10.0.19041.0, net10.0-windows10.0.19041.0 (WinUI), net9.0, net10.0 (cross-platform)

Serializer Compatibility

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: Configuration Made Easy

Akavache.Settings provides a specialized settings database for application configuration that survives app updates and reinstalls.

Quick Settings Example

using Akavache.Settings;

// 1. Create a settings class
public class AppSettings : SettingsBase
{
    public AppSettings() : base(nameof(AppSettings)) { }

    public bool EnableNotifications
    {
        get => GetOrCreate(true);  // Default: true
        set => SetOrCreate(value);
    }

    public string UserName
    {
        get => GetOrCreate("DefaultUser");
        set => SetOrCreate(value);
    }

    public int MaxRetries
    {
        get => GetOrCreate(3);
        set => SetOrCreate(value);
    }
}

// 2. Initialize with your app
var appSettings = default(AppSettings);

AppBuilder.CreateSplatBuilder()
    .WithAkavache<SystemJsonSerializer>(builder =>
        builder.WithApplicationName("MyApp")
               .WithSqliteProvider()
               .WithSettingsStore<AppSettings>(settings => appSettings = settings));

// 3. Use the settings
appSettings.EnableNotifications = false;
appSettings.UserName = "John Doe";
appSettings.MaxRetries = 5;

Console.WriteLine($"User: {appSettings.UserName}");
Console.WriteLine($"Notifications: {appSettings.EnableNotifications}");

Settings are automatically persisted and will survive app updates, making them perfect for user preferences and application configuration.

Documentation

๐Ÿ“š Complete documentation is available in the /docs folder:

Support and Contributing

Thanks

This project is tested with BrowserStack.

We want to thank the following contributors and libraries that help make Akavache possible:

Core Libraries

  • SQLite: sqlite-net-pcl and SQLitePCLRaw - Essential SQLite support for .NET
  • System.Reactive: Reactive Extensions for .NET - The foundation of Akavache's asynchronous API
  • Splat: Splat - Cross-platform utilities and service location
  • System.Text.Json: Microsoft's high-performance JSON serializer
  • Newtonsoft.Json: James Newton-King's Json.NET - The most popular .NET JSON library

Microsoft

We thank Microsoft for their ongoing support of the .NET ecosystem and the development tools that make Akavache possible.

License

Akavache is licensed under the MIT License.

  • Any 0.0
    • Akavache.SQLite3 (= 5.1.0-alpha0008)

Owners

Authors

Paul Betts

Project URL

https://github.com/akavache/akavache

License

MIT

Tags

Akavache Cache Xamarin Sqlite3 Magic

Info

926 total downloads
24 downloads for version 5.1.0-alpha0008
Download (2.72 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
6.3.2 82.02 KB Fri, 01 Feb 2019 23:15:17 GMT 0
6.3.1 82.01 KB Fri, 25 Jan 2019 06:19:46 GMT 0
6.2.7 82.06 KB Fri, 25 Jan 2019 06:10:43 GMT 0
6.2.3 81.42 KB Thu, 27 Dec 2018 10:33:42 GMT 0
6.2.2 81.45 KB Thu, 27 Dec 2018 09:12:10 GMT 0
6.2.1 81.4 KB Thu, 27 Dec 2018 01:48:41 GMT 0
6.1.8 81.41 KB Thu, 27 Dec 2018 01:41:14 GMT 1
6.1.7 81.39 KB Thu, 27 Dec 2018 01:34:17 GMT 1
6.1.6 81.36 KB Thu, 27 Dec 2018 01:25:45 GMT 0
6.1.5 81.4 KB Thu, 27 Dec 2018 01:14:48 GMT 0
6.1.4 81.35 KB Thu, 27 Dec 2018 00:51:49 GMT 0
6.1.3 81.42 KB Mon, 24 Dec 2018 19:13:23 GMT 1
6.1.2 81.43 KB Mon, 24 Dec 2018 06:21:11 GMT 0
6.1.1 81.39 KB Sun, 23 Dec 2018 00:47:57 GMT 1
6.0.36 81.37 KB Sun, 23 Dec 2018 00:35:33 GMT 2
6.0.35 81.43 KB Sun, 23 Dec 2018 00:11:30 GMT 0
6.0.34 81.36 KB Sun, 23 Dec 2018 00:05:04 GMT 1
6.0.33 11.16 KB Sat, 22 Dec 2018 00:06:27 GMT 1
6.0.31 11.15 KB Thu, 08 Nov 2018 13:35:43 GMT 2
6.0.30 11.15 KB Tue, 16 Oct 2018 15:39:49 GMT 1
6.0.27 11.16 KB Mon, 01 Oct 2018 23:10:58 GMT 2
6.0.24 11.16 KB Sat, 15 Sep 2018 18:08:45 GMT 1
6.0.23 11.16 KB Sat, 15 Sep 2018 18:04:40 GMT 4
6.0.22 11.16 KB Thu, 13 Sep 2018 20:29:38 GMT 7
6.0.20 11.16 KB Wed, 05 Sep 2018 14:49:13 GMT 1
6.0.19-beta 11.17 KB Wed, 29 Aug 2018 18:06:14 GMT 0
6.0.18-beta 11.17 KB Wed, 29 Aug 2018 12:53:42 GMT 0
6.0.17-beta 11.16 KB Fri, 24 Aug 2018 13:41:44 GMT 3
6.0.0-alpha0038 2.12 KB Sun, 03 Sep 2017 10:33:56 GMT 40
5.1.0-alpha0037 2.12 KB Sun, 03 Sep 2017 09:51:53 GMT 7
5.1.0-alpha0036 2.13 KB Sun, 03 Sep 2017 09:27:46 GMT 2
5.1.0-alpha0035 2.12 KB Fri, 25 Aug 2017 20:53:10 GMT 14
5.1.0-alpha0008 2.72 KB Sat, 20 May 2017 10:31:20 GMT 24
5.1.0-alpha0005 2.71 KB Wed, 05 Apr 2017 21:33:37 GMT 1
5.1.0-alpha0004 2.72 KB Mon, 23 Jan 2017 09:26:57 GMT 6
5.1.0-alpha0003 2.71 KB Mon, 16 Jan 2017 19:54:10 GMT 0
5.1.0-alpha0002 2.69 KB Fri, 04 Nov 2016 16:17:56 GMT 12
5.0.1-ghuntley-patch--0001 2.7 KB Fri, 04 Nov 2016 16:09:10 GMT 3
5.0.0.1478269438 3.05 KB Fri, 04 Nov 2016 14:25:28 GMT 543
5.0.0.1477562522 3.05 KB Thu, 27 Oct 2016 10:03:30 GMT 65
5.0.0.1476383622 3.05 KB Thu, 13 Oct 2016 18:35:07 GMT 80
5.0.0 2.67 KB Fri, 04 Nov 2016 15:08:05 GMT 38
4.2.0-alpha0075 2.69 KB Fri, 04 Nov 2016 14:43:58 GMT 1
4.1.3-beta0001 2.69 KB Fri, 04 Nov 2016 14:35:52 GMT 61