StoneKit.DataStore
1.24.703.121206
See the version list below for details.
dotnet add package StoneKit.DataStore --version 1.24.703.121206
NuGet\Install-Package StoneKit.DataStore -Version 1.24.703.121206
<PackageReference Include="StoneKit.DataStore" Version="1.24.703.121206" />
paket add StoneKit.DataStore --version 1.24.703.121206
#r "nuget: StoneKit.DataStore, 1.24.703.121206"
// Install StoneKit.DataStore as a Cake Addin #addin nuget:?package=StoneKit.DataStore&version=1.24.703.121206 // Install StoneKit.DataStore as a Cake Tool #tool nuget:?package=StoneKit.DataStore&version=1.24.703.121206
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<MyData>(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<MyData> 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(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.
Example Configuration
builder.Services.AddDataStore<MyData>(options =>
{
options.DirectoryPath = Path.Combine(builder.Environment.ContentRootPath, "DataStore");
options.FileLifetime = TimeSpan.FromDays(7);
options.CleanupInterval = TimeSpan.FromHours(1);
});
Example Usage
Saving Data
public class MyDataService
{
private readonly DataStore<MyData> _dataStore;
public MyDataService(DataStore<MyData> dataStore)
{
_dataStore = dataStore;
}
public async Task<string> SaveDataAsync(MyData data)
{
return await _dataStore.SaveAsync(data);
}
}
Loading Data
public class MyDataService
{
private readonly DataStore<MyData> _dataStore;
public MyDataService(DataStore<MyData> dataStore)
{
_dataStore = dataStore;
}
public async Task<MyData?> LoadDataAsync(string id)
{
return await _dataStore.LoadAsync(id);
}
}
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
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 | 93 | 10/5/2024 |
2024.1.1.305385 | 89 | 8/5/2024 |
2024.1.1.268769 | 94 | 7/9/2024 |
2024.1.1.261674 | 102 | 7/4/2024 |
2024.1.1.261665 | 104 | 7/4/2024 |
2024.1.1.261630 | 87 | 7/4/2024 |
2024.1.1.260673 | 101 | 7/3/2024 |
2024.1.1.260489 | 90 | 7/3/2024 |
2024.1.1.260485 | 103 | 7/3/2024 |
1.24.703.180759 | 99 | 7/3/2024 |
1.24.703.164606 | 94 | 7/3/2024 |
1.24.703.121206 | 87 | 7/3/2024 |
1.24.626.193110 | 110 | 6/26/2024 |