Proxfield.Extensions.Caching.SQLite.DependencyInjection 1.1.3

dotnet add package Proxfield.Extensions.Caching.SQLite.DependencyInjection --version 1.1.3
NuGet\Install-Package Proxfield.Extensions.Caching.SQLite.DependencyInjection -Version 1.1.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Proxfield.Extensions.Caching.SQLite.DependencyInjection" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Proxfield.Extensions.Caching.SQLite.DependencyInjection --version 1.1.3
#r "nuget: Proxfield.Extensions.Caching.SQLite.DependencyInjection, 1.1.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Proxfield.Extensions.Caching.SQLite.DependencyInjection as a Cake Addin
#addin nuget:?package=Proxfield.Extensions.Caching.SQLite.DependencyInjection&version=1.1.3

// Install Proxfield.Extensions.Caching.SQLite.DependencyInjection as a Cake Tool
#tool nuget:?package=Proxfield.Extensions.Caching.SQLite.DependencyInjection&version=1.1.3

<p align="center"> <img src="https://github.com/proxfield/Proxfield.Extensions.Caching.SQLite/assets/7343019/967483a9-c62e-4730-99a3-5f1b1aa0e358" /> </p>

The SQLite Caching Library is layer for caching data on SQLite to be used as a secondary database in case of failures and network inconsistences.

GitHub License Actions Nuget GitHub branch checks state GitHub code size in bytes

Packages

Packages and versions available at the Nuget Galery.

Package Version Downloads
<b>Proxfield.Extensions.Caching.SQLite</b> Nuget version Nuget downloads
<b>Proxfield.Extensions.Caching.SQLite.DependencyInjection</b> Nuget version Nuget downloads

Nuget

PM> Install-Package Proxfield.Extensions.Caching.SQLite

For application who uses Microsoft.Extensions.DependencyInjection there is a package available for using the library with DI:

PM> Install-Package Proxfield.Extensions.Caching.SQLite.DependencyInjection

Visit out project at the Nuget Repository Page to know more.

How

This caching library is based on the "Microsoft.Extensions.Caching.Redis" for memory caching, but instead of using Redis it uses the SQLite as a data layer. The ideia is to be a library for persistence cache in case of failures. This library uses the "Microsoft.Data" and acts as a layer above the SQLite.

Usage

The initialization can be either by using Microsoft's dependency injection or a common initialization.

Common Initialization

var cache = new SQLiteCache(options =>
{
    options.Location = @"c:\cache\database.sqlite";
});

Dependency Injection Initialization

services.AddSQLiteCache(options => {
    options.Location = @"c:\cache\database.sqlite";
});

Database file location

If the options.Location is not provided the database will be stored on the same folder as the projet which implement the library is running.

Encryption

To enable the encryption of all the data on the caching database one's just need to set the UseEncryption to true and set the EncryptionKey to any string, as shown bellow:

services.AddSQLiteCache(options => {
    options.UseEncryption = true;
    options.EncryptionKey = "d5644e8105ad77c3c3324ba693e83d8fffd54950"
});

Cache Methods available

The caching can be recorded/retrieved as a simple string

this.cache.SetAsString("users/1", "jose");
var user = this.cache.GetAsString("users/1");

Or either as a complex object:

this.cache.SetAsObject<User>("users/1", new User() { Name = "Jose" });
var user = this.cache.GetAsObject<User>("users/1");

The following list constains all caching methods avaliable currently on the library.

Method Description
byte[] Get(string key); Retrieves a cached resource from the database
Task<byte[]> GetAsync(string key); Retrieves a cached resource from the database as async
void Set(string key, byte[] value); Sets a cached resource to the database
Task SetAsync(string key, byte[] value); Sets a cached resource to the database async
void Remove(string key); Removes a cached resource to the database
Task RemoveAsync(string key); Removes a cached resource to the database as async
void SetAsString(string key, string value); Sets an string into the the database
void SetAsObject<T>(string key, T value); Sets an object into the the database
string GetAsString(string key); Retrieves a string from the database
T? GetAsObject<T>(string key); Retrieves an object from the database
List<T> GetAsObjectStartsWith<T>(this ISQLiteCache cache, string key) Get a list of objects when the key starts with something
List<string> GetAsStringStartsWith(this ISQLiteCache cache, string key) Get a list of strings when the key starts with something

Collections and Indexes

It is now possible to cache objects/strings by using an index, for example, the following code on a newly created database would save the object with the key as being <strong>vehicles/1</strong>.

 cache.SetAsObject("vehicles|", new { Name = "bycicle" }) ;

Making possible to query more than one object at once, every document on a collection.

cache.GetAsObjectStartsWith<Vehicle>("vehicles");

The following list constains all indexing methods avaliable currently on the library. They can be acessed by the Maintenance property of cache (<strong>cache.Maintenance.</strong>)

Method Description
List<SQLiteCacheIndex> GetAllIndexes() Returns all indexes on the database
SQLiteCacheIndex? GetIndex(string name Returns an index from the database
void ClearAllIndexers() Purge all indexes from the database
void ResetIndex(string name, long? value = null) Reset an index to an specific value

Platform Support

SQLite Caching is compiled for the following versions of frameworks:

  • DotNet 6
  • DotNet 5
  • DotNet Core 3.1

License

GitHub License

The MIT License (MIT) - Copyright (c) 2022-2023 Proxfield Consulting Group and its affiliates

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 205 8/10/2023
1.1.2 188 7/22/2023
1.1.1 152 7/22/2023
1.1.0 166 7/22/2023
1.0.4 477 9/22/2022
1.0.3 420 8/3/2022
1.0.2 395 8/3/2022
1.0.1 396 8/3/2022
1.0.0 399 8/2/2022
0.3.4 422 7/29/2022
0.3.3 409 7/29/2022
0.3.2 424 7/20/2022
0.3.1 409 7/20/2022
0.3.0 425 7/20/2022
0.2.6 463 7/13/2022
0.2.5 460 7/13/2022
0.2.4 466 7/13/2022
0.2.3 441 7/12/2022
0.2.2 445 7/12/2022