Hexalith.KeyValueStorages
1.4.0
See the version list below for details.
dotnet add package Hexalith.KeyValueStorages --version 1.4.0
NuGet\Install-Package Hexalith.KeyValueStorages -Version 1.4.0
<PackageReference Include="Hexalith.KeyValueStorages" Version="1.4.0" />
<PackageVersion Include="Hexalith.KeyValueStorages" Version="1.4.0" />
<PackageReference Include="Hexalith.KeyValueStorages" />
paket add Hexalith.KeyValueStorages --version 1.4.0
#r "nuget: Hexalith.KeyValueStorages, 1.4.0"
#addin nuget:?package=Hexalith.KeyValueStorages&version=1.4.0
#tool nuget:?package=Hexalith.KeyValueStorages&version=1.4.0
Hexalith Key/Value Storages
Overview
Hexalith Key/Value Storages is a flexible and extensible key-value storage library for .NET applications. It provides both in-memory and file-based storage implementations with support for optimistic concurrency control through Etags.
Purpose
The library offers a robust foundation for implementing key-value storage solutions with the following features:
- Generic type support for both keys and values
- Optimistic concurrency control using Etags
- Multiple storage implementations:
- In-memory storage for fast, temporary data
- File-based storage with JSON serialization
- Extensible architecture through interfaces
- Thread-safe operations
- Asynchronous API support
Getting Started
Prerequisites
- .NET 8.0 or later
- For file-based storage: Write permissions to the storage directory
Installation
Add the NuGet package to your project:
dotnet add package Hexalith.KeyValueStorages
Basic Usage
- In-Memory Storage:
// Create an in-memory store
var store = new InMemoryKeyValueStore<string, MyData>();
// Add a value
long etag = await store.AddAsync("key1", new MyData(), CancellationToken.None);
// Retrieve a value
var result = await store.GetAsync("key1", CancellationToken.None);
MyData value = result.Value;
long currentEtag = result.Etag;
// Update a value
long newEtag = await store.SetAsync("key1", updatedData, currentEtag, CancellationToken.None);
- JSON File Storage:
// Create a JSON file store
var store = new JsonFileKeyValueStorage<string, MyData>("data-directory");
// Operations are similar to in-memory store
string etag = await store.AddAsync("key1", new MyData(), CancellationToken.None);
Architecture
Core Interfaces
IKeyValueStore<TKey, TValue, TEtag>
: The main interface defining key-value store operationsIKeySerializer<TKey>
: Interface for key serializationIValueSerializer<TValue, TEtag>
: Interface for value serialization with Etag support
Implementations
In-Memory Storage:
InMemoryKeyValueStore<TKey, TValue>
: Simple in-memory implementation with long-based EtagsInMemoryKeyValueStore<TKey, TValue, TEtag>
: Base class supporting custom Etag types
Features
Optimistic Concurrency
The library implements optimistic concurrency control using Etags:
- Each value has an associated Etag
- Updates require the current Etag
- Concurrent modifications are detected and prevented
Thread Safety
All implementations are thread-safe:
- In-memory store uses internal locking
- File-based store uses file system locks
Extensibility
Create custom implementations by:
- Implementing
IKeyValueStore<TKey, TValue, TEtag>
- Extending base classes for specific storage types
- Creating custom serializers implementing
IKeySerializer<TKey>
orIValueSerializer<TValue, TEtag>
Learn More
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Hexalith.Commons.UniqueIds (>= 1.65.1)
- Hexalith.KeyValueStorages.Abstractions (>= 1.4.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Hexalith.KeyValueStorages:
Package | Downloads |
---|---|
Hexalith.KeyValueStorages.Files
Hexalith KeyValueStorages utilities and helpers |
|
Hexalith.KeyValueStorages.DaprComponents
Hexalith KeyValueStorages utilities and helpers |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.2 | 94 | 4/12/2025 |
2.1.1 | 128 | 4/11/2025 |
2.1.0 | 138 | 4/11/2025 |
2.0.2 | 161 | 4/10/2025 |
2.0.1 | 157 | 4/10/2025 |
2.0.0 | 166 | 4/10/2025 |
1.6.0 | 157 | 4/9/2025 |
1.5.0 | 153 | 4/8/2025 |
1.4.2 | 157 | 4/8/2025 |
1.4.1 | 161 | 4/7/2025 |
1.4.0 | 159 | 4/7/2025 |
1.3.2 | 151 | 4/6/2025 |
1.3.1 | 152 | 4/6/2025 |
1.3.0 | 160 | 4/6/2025 |
1.2.0 | 159 | 4/6/2025 |
1.1.0 | 117 | 4/4/2025 |
1.0.0 | 142 | 4/4/2025 |