Sloop 2.1.1

dotnet add package Sloop --version 2.1.1
                    
NuGet\Install-Package Sloop -Version 2.1.1
                    
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="Sloop" Version="2.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sloop" Version="2.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Sloop" />
                    
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 Sloop --version 2.1.1
                    
#r "nuget: Sloop, 2.1.1"
                    
#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 Sloop@2.1.1
                    
#: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=Sloop&version=2.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Sloop&version=2.1.1
                    
Install as a Cake Tool

Sloop

Maintainability Rating Code Coverage Reliability Rating Security Rating

Sloop logo

Sloop is a lightweight, PostgreSQL-backed implementation of IDistributedCache for .NET applications. It provides durable, high-performance caching with support for sliding and absolute expiration. Designed for simplicity and resilience in distributed systems.

✨ Features

  • ⚡ Distributed key-value store backed by PostgreSQL
  • 🕓 Support for sliding and absolute expiration
  • 🔁 Safe for multi-instance use
  • 🧹 Periodic cleanup of expired entries
  • 🧪 Fully integration-tested with high coverage
  • 📦 Compatible with Microsoft.Extensions.Caching.Abstractions
  • 🐘 Powered by Npgsql and Dapper
  • 💉 Simple, idiomatic DI registration

📦 Installation

dotnet add package Sloop

Requires .NET 8.0 SDK or later

🚀 Quick Start

Register with Dependency Injection

builder.Services.AddCache(options =>
{
    options.UseConnectionString(builder.Configuration.GetConnectionString("Cache")!);
    options.SchemaName = "public";
    options.TableName = "cache";
    options.DefaultSlidingExpiration = TimeSpan.FromMinutes(5);
    options.DefaultAbsoluteExpiration = TimeSpan.FromMinutes(30);
    options.CleanupInterval = TimeSpan.FromMinutes(1);
    options.CreateInfrastructure = true;
});

Use IDistributedCache

public class MyService
{
    private readonly IDistributedCache _cache;

    public MyService(IDistributedCache cache)
    {
        _cache = cache;
    }

    public async Task UseCacheAsync()
    {
        var key = "user:123";
        var data = await _cache.GetStringAsync(key);

        if (data == null)
        {
            data = "example";
            await _cache.SetStringAsync(key, data, new DistributedCacheEntryOptions
            {
                SlidingExpiration = TimeSpan.FromMinutes(10),
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1)
            });
        }
    }
}

🧪 Testing

Tests are executed against disposable PostgreSQL containers via Testcontainers:

dotnet test

🏎 Benchmark Results

Tested on: Intel i5-14600K, Arch Linux, .NET 8.0

Method Parallelism Mean Allocated
SetAsync 1 60.05 µs 5.81 KB
GetAsync 1 73.15 µs 3.76 KB
SetAsync_Parallel 1 60.00 µs 6.01 KB
GetAsync_Parallel 1 66.78 µs 4.14 KB
SetAsync 10 60.10 µs 5.81 KB
GetAsync 10 64.30 µs 3.76 KB
SetAsync_Parallel 10 580.55 µs 56.08 KB
GetAsync_Parallel 10 840.78 µs 36.81 KB
SetAsync 50 61.44 µs 5.81 KB
GetAsync 50 64.80 µs 3.76 KB
SetAsync_Parallel 50 872.56 µs 278.38 KB
GetAsync_Parallel 50 2029.80 µs 181.87 KB

Benchmarks run using BenchmarkDotNet on .NET 8.0 with Testcontainers for PostgreSQL.

🤝 Contributing

Contributions are welcome! Please follow standard C# coding guidelines and include tests with pull requests.

📄 License

Licensed under the MIT License.

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.  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

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
2.1.1 490 7/23/2025
2.1.0 484 7/23/2025
2.0.0 439 7/21/2025
1.0.3 143 5/29/2025
1.0.2 144 5/29/2025
1.0.1 147 5/27/2025
1.0.0 85 5/23/2025