Sloop 2.1.1
dotnet add package Sloop --version 2.1.1
NuGet\Install-Package Sloop -Version 2.1.1
<PackageReference Include="Sloop" Version="2.1.1" />
<PackageVersion Include="Sloop" Version="2.1.1" />
<PackageReference Include="Sloop" />
paket add Sloop --version 2.1.1
#r "nuget: Sloop, 2.1.1"
#:package Sloop@2.1.1
#addin nuget:?package=Sloop&version=2.1.1
#tool nuget:?package=Sloop&version=2.1.1
Sloop
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 | 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. 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. |
-
net8.0
- Dapper (>= 2.1.66)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Options (>= 9.0.5)
- Npgsql (>= 9.0.3)
-
net9.0
- Dapper (>= 2.1.66)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Options (>= 9.0.5)
- Npgsql (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.