Cachey.Persistence.SQLite 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cachey.Persistence.SQLite --version 1.0.2
                    
NuGet\Install-Package Cachey.Persistence.SQLite -Version 1.0.2
                    
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="Cachey.Persistence.SQLite" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cachey.Persistence.SQLite" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Cachey.Persistence.SQLite" />
                    
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 Cachey.Persistence.SQLite --version 1.0.2
                    
#r "nuget: Cachey.Persistence.SQLite, 1.0.2"
                    
#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.
#:package Cachey.Persistence.SQLite@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cachey.Persistence.SQLite&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Cachey.Persistence.SQLite&version=1.0.2
                    
Install as a Cake Tool

Cachey

Cachey is a lightweight, modular, and extensible caching library designed to provide in-memory and persistent caching mechanisms with configurable expiration and cleanup policies.

Features

  • In-Memory Cache: High-performance caching for frequently accessed data.
  • Persistent Cache: Optional persistent storage with SQLite support.
  • Expiration Policies: Configurable item expiration times.
  • Background Cleanup: Periodic removal of expired items for optimal memory usage.
  • Metrics: Tracks cache hits, misses, and overall performance.

Installation

Cachey is distributed as a .NET library. To install, use the NuGet package manager:

dotnet add package Cachey

Usage

Basic Setup

To start using Cachey, initialize an instance of the Cache class:

var cache = new Cache();

Adding and Retrieving Items

await cache.SetAsync("key", "value", TimeSpan.FromMinutes(5));
var value = await cache.GetAsync<string>("key");

Checking for Existence

bool exists = await cache.ContainsAsync("key");

Removing Items

await cache.RemoveAsync("key");

Clearing the Cache

await cache.ClearAsync();

Background Cleanup Service

Cachey includes a background cleanup service to remove expired items automatically. You can configure and start it as follows:

var cleanupService = new BackgroundCleanupService(cache, TimeSpan.FromSeconds(30));
cleanupService.Start();

Metrics

Metrics provide insights into cache performance:

var metrics = cache.GetMetrics();
Console.WriteLine($"Hits: {metrics.Hits}, Misses: {metrics.Misses}");

Persistent Caching

To enable persistent caching with SQLite:

  1. Add the Cachey.Persistence.SQLite package:

    dotnet add package Cachey.Persistence.SQLite
    
  2. Use the SqliteCacheRepository:

    var options = new DbContextOptionsBuilder<CacheyDbContext>()
        .UseSqlite("Data Source=cachey.db")
        .Options;
    
    var context = new CacheyDbContext(options);
    var persistentCache = new SqliteCacheRepository(context);
    
    var cache = new Cache(persistentCache);
    

Testing

Cachey includes a suite of tests to ensure reliability. To run the tests, use:

dotnet test

Contributions

Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.

License

Cachey is licensed under the MIT License. See the LICENSE file for more 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Cachey.Persistence.SQLite:

Package Downloads
Cachey.Core

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 182 12/6/2024
1.0.2 168 12/5/2024
1.0.1 173 12/5/2024