StoneKit.DataStore
2024.1.1.268769
See the version list below for details.
dotnet add package StoneKit.DataStore --version 2024.1.1.268769
NuGet\Install-Package StoneKit.DataStore -Version 2024.1.1.268769
<PackageReference Include="StoneKit.DataStore" Version="2024.1.1.268769" />
paket add StoneKit.DataStore --version 2024.1.1.268769
#r "nuget: StoneKit.DataStore, 2024.1.1.268769"
// Install StoneKit.DataStore as a Cake Addin #addin nuget:?package=StoneKit.DataStore&version=2024.1.1.268769 // Install StoneKit.DataStore as a Cake Tool #tool nuget:?package=StoneKit.DataStore&version=2024.1.1.268769
StoneKit DataStore
StoneKit DataStore is a lightweight, high-performance data storage library for .NET Core 8+ applications. It allows for simple and efficient storage and retrieval of objects by ID, with optional background cleanup of old files based on configurable settings.
Installation
You can install StoneKit.DataStore via NuGet Package Manager:
PM> Install-Package StoneKit.DataStore
Features
Simple Storage and Retrieval:
- Store and retrieve objects by ID.
- Automatically generate IDs based on object content if not provided.
Background Cleanup:
- Configurable background task to delete old files based on a specified lifespan.
Asynchronous Operations:
- Utilizes asynchronous file operations for optimal performance.
Configuration Options:
- Configure storage path, file lifetime, and cleanup interval at application startup.
Usage
Setting up your project
Configure Services:
In your
Program.cs
, use theAddDataStore
extension method to configure the data store.
using Microsoft.Extensions.DependencyInjection;
using SimpleDataStore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDataStore(options =>
{
options.DirectoryPath = Path.Combine(builder.Environment.ContentRootPath, "DataStore"); // Or null
options.FileLifetime = TimeSpan.FromDays(7); // Or null
options.CleanupInterval = TimeSpan.FromHours(1); // Or null
});
var app = builder.Build();
app.MapGet("/", async (DataStore dataStore) =>
{
// Example data
var data = new MyData { Content = "Example Data" };
// Save the data
var id = await dataStore.SaveAsync(data);
// Retrieve the data
var retrievedData = await dataStore.LoadAsync<MyData>(id);
return Results.Ok(retrievedData);
});
app.Run();
Data Model:
Define your data model.
public class MyData { /// <summary> /// Gets or sets the content of the data. /// </summary> public string Content { get; set; } }
Configuration Options
You can configure the data store with the following options:
- DirectoryPath: Optional; The directory path where data will be stored.
- FileLifetime: Optional; The time span after which files should be considered for cleanup.
- CleanupInterval: Optional; The interval at which the cleanup task will run.
- EncryptionKey: Optional; An encryption key used for encrypting/decrypting the stored data using AES. No encryption will be used if left blank or null.
Example Configuration
builder.Services.AddDataStore(options =>
{
options.DirectoryPath = Path.Combine(builder.Environment.ContentRootPath, "DataStore");
options.FileLifetime = TimeSpan.FromDays(7);
options.CleanupInterval = TimeSpan.FromHours(1);
options.EncryptionKey = "Some_Secret_Key";
});
Example Usage
Saving Data
public class MyDataService
{
private readonly DataStore _dataStore;
public MyDataService(DataStore dataStore)
{
_dataStore = dataStore;
}
public async Task<string> SaveDataAsync(MyData data)
{
return await _dataStore.SaveAsync(data);
}
}
Loading Data
public class MyDataService
{
private readonly DataStore _dataStore;
public MyDataService(DataStore dataStore)
{
_dataStore = dataStore;
}
public async Task<MyData?> LoadDataAsync(string id)
{
var result = await _dataStore.LoadAsync<MyData>(id);
return result.HasValue ? result.Value : null;
}
}
Contributions
Contributions and feedback are welcome! Feel free to submit issues, feature requests, or pull requests on the GitHub repository.
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 | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- StoneKit.Core.Structs.Maybe (>= 2024.1.1.260673)
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 |
---|---|---|
2024.1.1.391401 | 83 | 10/5/2024 |
2024.1.1.305385 | 84 | 8/5/2024 |
2024.1.1.268769 | 89 | 7/9/2024 |
2024.1.1.261674 | 97 | 7/4/2024 |
2024.1.1.261665 | 99 | 7/4/2024 |
2024.1.1.261630 | 83 | 7/4/2024 |
2024.1.1.260673 | 96 | 7/3/2024 |
2024.1.1.260489 | 84 | 7/3/2024 |
2024.1.1.260485 | 98 | 7/3/2024 |
1.24.703.180759 | 93 | 7/3/2024 |
1.24.703.164606 | 88 | 7/3/2024 |
1.24.703.121206 | 82 | 7/3/2024 |
1.24.626.193110 | 105 | 6/26/2024 |