TheAdvDistributedOutputCache 1.0.10
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TheAdvDistributedOutputCache --version 1.0.10
NuGet\Install-Package TheAdvDistributedOutputCache -Version 1.0.10
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="TheAdvDistributedOutputCache" Version="1.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TheAdvDistributedOutputCache" Version="1.0.10" />
<PackageReference Include="TheAdvDistributedOutputCache" />
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 TheAdvDistributedOutputCache --version 1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TheAdvDistributedOutputCache, 1.0.10"
#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 TheAdvDistributedOutputCache@1.0.10
#: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=TheAdvDistributedOutputCache&version=1.0.10
#tool nuget:?package=TheAdvDistributedOutputCache&version=1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TheAdvDistributedOutputCache
TheAdvDistributedOutputCache là middleware Output Caching nâng cao cho ASP.NET Core (.NET 9), hỗ trợ:
✅ Redis + Local Memory Cache
✅ Distributed Lock (RedLock) tránh cache stampede
✅ Per-route TTL Cache
✅ Cache Busting tự động khi có PUT/POST/DELETE
✅ Xóa cache theo pattern & nhiều key liên quan
✅ Redis Key Prefix riêng cho từng project
🚀 Cài đặt
Bạn có thể cài trực tiếp từ NuGet.org:
dotnet add package TheAdvDistributedOutputCache
<PackageReference Include="TheAdvDistributedOutputCache" Version="1.0.*" />
1. Cấu hình appsettings.json
{
"CacheOptions": {
"Prefix": "productA:cache:"
}
}
2. Đăng ký Redis Cache + Middleware Trong Program.cs:
using DistributedOutputCache.Cache;
using DistributedOutputCache.Models;
using DistributedOutputCache.Middleware;
using StackExchange.Redis;
var builder = WebApplication.CreateBuilder(args);
// ✅ Load Redis Key Prefix từ cấu hình
builder.Services.Configure<CacheOptions>(
builder.Configuration.GetSection("CacheOptions")
);
// ✅ Đăng ký Redis & Cache
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<IConnectionMultiplexer>(
ConnectionMultiplexer.Connect("localhost:6379")
);
builder.Services.AddSingleton<ILocalCacheService, LocalCacheService>();
builder.Services.AddSingleton<IRedisLockHelper>(
sp => new RedisLockHelper(new[] { "localhost:6379" })
);
builder.Services.AddSingleton<ICacheService, CacheService>();
builder.Services.AddControllers();
var app = builder.Build();
// TTL per-route
var cachePolicies = new List<CacheRoutePolicy>
{
new CacheRoutePolicy { Pattern = "/api/products/*", Ttl = TimeSpan.FromHours(1) },
new CacheRoutePolicy { Pattern = "/api/users/*", Ttl = TimeSpan.FromMinutes(5) }
};
// Cache busting rules
var bustingRules = new List<CacheBustingRule>
{
new CacheBustingRule
{
TriggerPattern = "/api/products/*",
BustPatterns = new[] { "httpcache:/api/products/*" }
},
new CacheBustingRule
{
TriggerPattern = "/api/users/*",
BustPatterns = new[]
{
"httpcache:/api/users/*",
"httpcache:/api/users/list*"
}
}
};
// ✅ Bật middleware Output Cache
app.UseOutputCache(TimeSpan.FromMinutes(10), cachePolicies, bustingRules);
app.MapControllers();
app.Run();
Cách hoạt động
GET /api/users/123 → cache response trong Redis + local memory
PUT /api/users/123 → tự động xóa cache httpcache:/api/users/123 + /api/users/list*
Distributed Lock tránh nhiều request cùng lúc hit DB
Per-route TTL → mỗi route có thời gian cache riêng
Yêu cầu
ASP.NET Core (.NET 9 trở lên)
Redis server (Standalone hoặc Cluster)
Tùy chọn
Prefix Redis Key → dễ quản lý nhiều project dùng chung Redis
Xóa cache theo pattern → busting nhiều key cùng lúc
Cache riêng từng user (future support)
Product | Versions 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.
-
net9.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.7)
- Microsoft.Extensions.Options (>= 9.0.7)
- RedLock.net (>= 2.3.2)
- StackExchange.Redis (>= 2.8.41)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.