StoneKit.DataStore 1.24.703.164606

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

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

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.305385 64 8/5/2024
2024.1.1.268769 71 7/9/2024
2024.1.1.261674 83 7/4/2024
2024.1.1.261665 85 7/4/2024
2024.1.1.261630 67 7/4/2024
2024.1.1.260673 80 7/3/2024
2024.1.1.260489 68 7/3/2024
2024.1.1.260485 84 7/3/2024
1.24.703.180759 79 7/3/2024
1.24.703.164606 72 7/3/2024
1.24.703.121206 64 7/3/2024
1.24.626.193110 91 6/26/2024