Hexalith.KeyValueStorages 1.4.0

There is a newer version of this package available.
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
                    
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="Hexalith.KeyValueStorages" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hexalith.KeyValueStorages" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Hexalith.KeyValueStorages" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hexalith.KeyValueStorages --version 1.4.0
                    
#r "nuget: Hexalith.KeyValueStorages, 1.4.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.
#addin nuget:?package=Hexalith.KeyValueStorages&version=1.4.0
                    
Install Hexalith.KeyValueStorages as a Cake Addin
#tool nuget:?package=Hexalith.KeyValueStorages&version=1.4.0
                    
Install Hexalith.KeyValueStorages as a Cake Tool

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

  1. 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);
  1. 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 operations
  • IKeySerializer<TKey>: Interface for key serialization
  • IValueSerializer<TValue, TEtag>: Interface for value serialization with Etag support

Implementations

  1. In-Memory Storage:

    • InMemoryKeyValueStore<TKey, TValue>: Simple in-memory implementation with long-based Etags
    • InMemoryKeyValueStore<TKey, TValue, TEtag>: Base class supporting custom Etag types
  2. File Storage.

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:

  1. Implementing IKeyValueStore<TKey, TValue, TEtag>
  2. Extending base classes for specific storage types
  3. Creating custom serializers implementing IKeySerializer<TKey> or IValueSerializer<TValue, TEtag>

Learn More

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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