vapolia-keyvaluelite 1.0.0

There is a newer version of this package available.
See the version list below for details.

Requires NuGet 2.5 or higher.

dotnet add package vapolia-keyvaluelite --version 1.0.0                
NuGet\Install-Package vapolia-keyvaluelite -Version 1.0.0                
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="vapolia-keyvaluelite" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add vapolia-keyvaluelite --version 1.0.0                
#r "nuget: vapolia-keyvaluelite, 1.0.0"                
#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 vapolia-keyvaluelite as a Cake Addin
#addin nuget:?package=vapolia-keyvaluelite&version=1.0.0

// Install vapolia-keyvaluelite as a Cake Tool
#tool nuget:?package=vapolia-keyvaluelite&version=1.0.0                

KeyValueLite

A netstandard key value store, backed by sqlite, alternative to Akavache

(c)2018-2019 Benjamin Mayrargue
MIT License

Features

  • Just works
  • Async operations
  • Thread safe
  • Fast enough
  • Direct write on underlying sqlite database. No need to flush.
  • Stores DateTime/DateTimeOffset using ticks, not strings, preserving nanoseconds
  • Akavache interface for easy and fast migration: use the KeyValueLiteLikeAkavache class.

Setup

Add to your netstandard project:

Add to your executable projects:

  • Add Microsoft.Extensions.Logging
  • SQLitePCLRaw.bundle_e_sqlite3
  • SQLite.Net-PCL (currently private)

Initialization code:

SQLitePCL.Batteries_V2.Init();

var loggerFactory = new Microsoft.Extensions.Logging.LoggerFactory();
var logger = new Microsoft.Extensions.Logging.Logger<KeyValueLite>(loggerFactory);

var dataStoreFactory = new DataStoreFactory(new SQLitePlatform(), new GenericPlatformService());
cacheService = new KeyValueLite(dataStoreFactory, new KeyValueItemNewtonsoftJsonSerializer(), logger);

Usage

Get a value, or create it if it does not exist

Usage scenario
Get an object from the cache, or create it synchronously
Get an object from the cache, or fetch it from a webservice. Optionaly set an expiration time.

Task<T> GetOrCreateObject<T>(string key, Func<T> create)
Task<T> GetOrFetchObject<T>(string key, Func<Task<T>> create, DateTimeOffset? expiresOn = null)

Samples:

var value = await GetOrCreateObject("sample key", () => "sample string value")
var value = await GetOrCreateObject("sample key", () => new SomeObject { SomeProperty = 12 })

var value = await GetOrFetchObject("sample key", async () => await httpClient.GetAync("https://happy/api/method"));

Add values

Add a list of value
Persists the specified key, value and expiration, updating it if the key already exists.

Task InsertObjects<T>(Dictionary<string, T> keyValuePairs, DateTimeOffset? expiresOn = null)
Task Set(string key, object value, DateTimeOffset? expiresOn = null)

Samples:

await InsertObjects(new Dictionary<string,IPAddress>() { {"someKey", someIp}, {"someKey2", someIp2} }, DateTimeOffset.Now.AddDays(1));
await Set("someKey", someObject, DateTimeOffset.Now.AddMinutes(60));

Retrieve a value

Usage scenario
Get an object from the cache, or null if it has expired or is not in the cache
Get all objects of this type from the cache

Task<T> Get<T>(string key)
Task<List<T>> GetAll<T>()

Samples:

var value = await Get<string>("sample key");
var values = await GetAll<string>();

Delete a value

Usage scenario
Delete an object from the cache Delete all objects of this type from the cache

Task Remove(string key)
Task RemoveAll<T>()

Samples:

await Remove("the key");
await RemoveAll<string>();

If the key does not exist, it does nothing.

Usage (advanced)

Get the internal keyValueItem matching this key, or null

var keyValueItem = await keyValueStore.Get("sample key");

Persists the specified KeyValueItem, updating it if the key already exists.

Task Set(KeyValueItem keyValueItem);

Removes the specified key value item.

Task Remove(KeyValueItem keyValueItem)

About Newtonsoft.Json

If you prefer not to use this Json library, implement your own IKeyValueItemSerializer and use the Core nuget.
See KeyValueItemNewtonsoftJsonSerializer for an example of IKeyValueItemSerializer implementation.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
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
3.0.1 448 3/19/2021
3.0.0 579 10/18/2019
2.0.0 534 8/19/2019
1.0.1 601 6/5/2019
1.0.0 593 4/15/2019