PolyCache 1.2.2
dotnet add package PolyCache --version 1.2.2
NuGet\Install-Package PolyCache -Version 1.2.2
<PackageReference Include="PolyCache" Version="1.2.2" />
<PackageVersion Include="PolyCache" Version="1.2.2" />
<PackageReference Include="PolyCache" />
paket add PolyCache --version 1.2.2
#r "nuget: PolyCache, 1.2.2"
#:package PolyCache@1.2.2
#addin nuget:?package=PolyCache&version=1.2.2
#tool nuget:?package=PolyCache&version=1.2.2
PolyCache — Distributed Cache Manager for .NET (Core)
PolyCache is a lightweight, flexible distributed cache manager for .NET applications. It provides a simple, unified API for caching with multiple backends, helping you boost performance, reduce load on data sources, and simplify cache handling across your app.
- Supported cache providers: Redis, in-memory, and SQL Server
- Simple DI registration
- Centralized, configurable cache times
- Drop-in interface:
IStaticCacheManager
Table of Contents
- Installation
- Quick Start
- Configuration
- Usage
- Setting Up Redis with Docker Compose
- Notes and Recommendations
Installation
You can install PolyCache via NuGet.
Package Manager:
Install-Package PolyCache
.NET CLI:
dotnet add package PolyCache
Quick Start
Register PolyCache in your application's dependency injection container.
ASP.NET Core (Startup.cs):
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddPolyCache(Configuration);
// ...
}
Minimal hosting (Program.cs, .NET 6+):
var builder = WebApplication.CreateBuilder(args);
// ...
builder.Services.AddPolyCache(builder.Configuration);
// ...
var app = builder.Build();
app.Run();
Configuration
PolyCache supports multiple providers with a simple configuration model. Add the following sections to your appsettings.json:
"CacheConfig": {
"DefaultCacheTime": 60,
"ShortTermCacheTime": 3,
"BundledFilesCacheTime": 120
},
"DistributedCacheConfig": {
"DistributedCacheType": "redis",
"Enabled": true,
"ConnectionString": "127.0.0.1:6379,ssl=False",
"SchemaName": "dbo",
"TableName": "DistributedCache"
}
CacheConfig
- DefaultCacheTime: Default cache lifetime (minutes) for most entries.
- ShortTermCacheTime: Shorter cache lifetime (minutes) for volatile entries.
- BundledFilesCacheTime: Cache lifetime (minutes) for bundled/static resources.
DistributedCacheConfig
- DistributedCacheType: One of
redis,memory, orsqlserver. - Enabled: Set to
trueto enable distributed caching. - ConnectionString: Provider-specific connection string (e.g., Redis endpoint).
- SchemaName (SQL Server only): Database schema for the cache table.
- TableName (SQL Server only): Table name used to store cache entries.
- DistributedCacheType: One of
Usage
Inject the IStaticCacheManager interface wherever you need caching.
public class MyService
{
private readonly IStaticCacheManager _cache;
public MyService(IStaticCacheManager cache)
{
_cache = cache;
}
// Use _cache to read/write cache entries, apply lifetimes, etc.
// See the sample project for concrete examples.
}
A sample project demonstrates typical usage patterns, including configuration and integration.
Setting Up Redis with Docker Compose
If you plan to use Redis as your cache provider, you can spin it up quickly with Docker:
- Install Docker for your OS.
- Download
redis-docker-compose.ymlfrom the sample project. - Open a terminal with administrative privileges.
- Navigate to the folder containing
redis-docker-compose.yml. - Start Redis:
docker-compose -f redis-docker-compose.yml up -d - Verify it's running:
docker ps - Update your
appsettings.jsonDistributedCacheConfig.ConnectionStringto point to your Redis instance (e.g.,127.0.0.1:6379,ssl=False).
Notes and Recommendations
- For development or single-instance scenarios,
memoryis convenient and fast. - For multi-instance or production scenarios,
redisis recommended for true distributed caching. - When using SQL Server, ensure
SchemaNameandTableNameare set and that the application has proper permissions. - Adjust the cache times in
CacheConfigto match your data volatility and freshness requirements.
Enjoy faster, simpler caching with PolyCache in your .NET applications!
| 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 was computed. 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
- Azure.Identity (>= 1.17.1)
- Microsoft.Data.SqlClient (>= 6.1.2)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Caching.SqlServer (>= 8.0.11)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.11)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Newtonsoft.Json (>= 13.0.4)
- Nito.AsyncEx.Coordination (>= 5.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on PolyCache:
| Repository | Stars |
|---|---|
|
omid-ahmadpour/CleanArchitecture-Template
This stands as a comprehensive solution template that embodies the principles of Clean Architecture, seamlessly integrated with the prowess of CQRS implementation, all within the ASP.NET Core framework.
|
Update to .NET 8.0