PolyCache 1.2.2

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

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

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, or sqlserver.
    • Enabled: Set to true to 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.

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:

  1. Install Docker for your OS.
  2. Download redis-docker-compose.yml from the sample project.
  3. Open a terminal with administrative privileges.
  4. Navigate to the folder containing redis-docker-compose.yml.
  5. Start Redis:
    docker-compose -f redis-docker-compose.yml up -d
    
  6. Verify it's running:
    docker ps
    
  7. Update your appsettings.json DistributedCacheConfig.ConnectionString to point to your Redis instance (e.g., 127.0.0.1:6379,ssl=False).

Notes and Recommendations

  • For development or single-instance scenarios, memory is convenient and fast.
  • For multi-instance or production scenarios, redis is recommended for true distributed caching.
  • When using SQL Server, ensure SchemaName and TableName are set and that the application has proper permissions.
  • Adjust the cache times in CacheConfig to match your data volatility and freshness requirements.

Enjoy faster, simpler caching with PolyCache in your .NET applications!

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 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. 
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 (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.
Version Downloads Last Updated
1.2.2 628 11/22/2025
1.2.1 4,211 5/8/2024
1.2.0 190 2/24/2024

Update to .NET 8.0