StoneKit.DataStore 2024.1.1.260489

There is a newer version of this package available.
See the version list below for details.
dotnet add package StoneKit.DataStore --version 2024.1.1.260489                
NuGet\Install-Package StoneKit.DataStore -Version 2024.1.1.260489                
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="StoneKit.DataStore" Version="2024.1.1.260489" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StoneKit.DataStore --version 2024.1.1.260489                
#r "nuget: StoneKit.DataStore, 2024.1.1.260489"                
#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 StoneKit.DataStore as a Cake Addin
#addin nuget:?package=StoneKit.DataStore&version=2024.1.1.260489

// Install StoneKit.DataStore as a Cake Tool
#tool nuget:?package=StoneKit.DataStore&version=2024.1.1.260489                

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

  1. Configure Services:

    In your Program.cs, use the AddDataStore 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();
  1. 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 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. 
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
2024.1.1.391401 91 10/5/2024
2024.1.1.305385 87 8/5/2024
2024.1.1.268769 92 7/9/2024
2024.1.1.261674 100 7/4/2024
2024.1.1.261665 102 7/4/2024
2024.1.1.261630 85 7/4/2024
2024.1.1.260673 99 7/3/2024
2024.1.1.260489 88 7/3/2024
2024.1.1.260485 101 7/3/2024
1.24.703.180759 97 7/3/2024
1.24.703.164606 92 7/3/2024
1.24.703.121206 85 7/3/2024
1.24.626.193110 108 6/26/2024