NetPro.ResponseCache
6.0.16
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
dotnet add package NetPro.ResponseCache --version 6.0.16
NuGet\Install-Package NetPro.ResponseCache -Version 6.0.16
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="NetPro.ResponseCache" Version="6.0.16" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.ResponseCache --version 6.0.16
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.ResponseCache, 6.0.16"
#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.
// Install NetPro.ResponseCache as a Cake Addin #addin nuget:?package=NetPro.ResponseCache&version=6.0.16 // Install NetPro.ResponseCache as a Cake Tool #tool nuget:?package=NetPro.ResponseCache&version=6.0.16
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ResponseCache使用
支持对响应缓存,同样的查询条件在缓存时间内直接返回之前的响应接口,降低响应时间
使用
appsetting.json
"ResponseCacheOption": {
"Enabled": true,//默认启用
"Cluster":false,
"Duration": 5,//响应持续时间
"IgnoreVaryByQueryKeys": [ "sign,timestamp" ]
}
启用服务
public void ConfigureServices(IServiceCollection services)
{
//响应缓存
services.AddResponseCachingExtension();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseShareRequestBody();//共享body流,UseShareRequestBody必须在UsePostResponseCache中间件之上,而且必须启用,否则响应缓存失效
app.UsePostResponseCache();//启动Post全局响应缓存,建议不使用全局Post缓存,改用特新方式[PostResponseCacheAttribute],除非在查询条件繁多情况下为了快速组装条件用Post提交条件方式进行查询可使用全局缓存,
app.UseGetResponseCaching();//启动Get全局响应缓存,也可直接使用[ResponseCache]特性对指定接口启用Get响应缓存
}
注意:优先级低于使用 [PostResponseCache(Duration = 10, Order = 1)]
使用
Get请求缓存配置
/// <summary>
/// 根据account检测账户
/// VaryByQueryKeys中的值将参与缓存,如以下接口,只要account参数值是同一个,无论sign参数如何变化始终将命中缓存
/// </summary>
/// <param name="account">用户名</param>
/// <param name="sign">签名,每次请求都将变化</param>
/// <returns></returns>
[HttpGet("action/exist")]
[ProducesResponseType(200)]
[ResponseCache(Duration = 10, VaryByQueryKeys = new[] { "account"})]
public async Task IsExistAccount(string account,string sign)
Post特性方式启用响应缓存配置
/// <summary>
/// 获取一个查询
/// </summary>
/// <param name="gg"></param>
/// <returns></returns>
[HttpPost]
[Route("pay/post")]
[ProducesResponseType(200)]
[ProducesResponseType(200, Type = typeof(XXXAo))]
[PostResponseCache(Duration = 10,ResponseMode =ResponseMode.Error,Message="请求频繁,稍后再试")]//响应缓存10秒
public IActionResult Cache([FromBody]XXXInput gg)
{
return BadRequest(new Result { Data = gg.Age, Code = 11 });
}
```
响应StatusCode为1001时为报错模式触发响应缓存
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- NetPro.CsRedis (>= 6.0.16)
- NetPro.NetProShareRequestBody (>= 6.0.16)
-
net6.0
- NetPro.CsRedis (>= 6.0.16)
- NetPro.NetProShareRequestBody (>= 6.0.16)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NetPro.ResponseCache:
Package | Downloads |
---|---|
NetPro.Web.Core
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.0.16 | 197 | 7/24/2023 |
6.0.15 | 418 | 7/19/2022 |
6.0.14 | 441 | 7/10/2022 |
6.0.13 | 452 | 6/15/2022 |
6.0.12 | 441 | 6/15/2022 |
6.0.11 | 411 | 6/15/2022 |
6.0.10 | 411 | 6/11/2022 |
6.0.9 | 418 | 6/8/2022 |
6.0.8 | 421 | 5/26/2022 |
6.0.8-beta.3 | 133 | 5/24/2022 |
6.0.8-beta.2 | 121 | 5/24/2022 |
6.0.7 | 409 | 5/18/2022 |
6.0.6 | 438 | 4/28/2022 |
6.0.5 | 415 | 3/30/2022 |
6.0.5-beta.20 | 129 | 4/27/2022 |
6.0.5-beta.19 | 129 | 4/25/2022 |
6.0.5-beta.18 | 123 | 4/22/2022 |
6.0.5-beta.17 | 141 | 4/16/2022 |
6.0.5-beta.16 | 139 | 4/8/2022 |
6.0.5-beta.15 | 134 | 4/8/2022 |
6.0.5-beta.14 | 141 | 4/7/2022 |
6.0.5-beta.13 | 145 | 4/7/2022 |
6.0.5-beta.12 | 137 | 4/6/2022 |
6.0.5-beta.11 | 139 | 4/6/2022 |
6.0.5-beta.10 | 134 | 3/31/2022 |
6.0.5-beta.9 | 142 | 3/26/2022 |
6.0.5-beta.8 | 139 | 3/22/2022 |
6.0.5-beta.7 | 138 | 3/21/2022 |
6.0.5-beta.6 | 136 | 3/14/2022 |
6.0.5-beta.5 | 139 | 3/2/2022 |
6.0.5-beta.4 | 138 | 2/22/2022 |
6.0.5-beta.3 | 140 | 2/18/2022 |
6.0.5-beta.2 | 138 | 2/18/2022 |
6.0.5-beta.1 | 135 | 2/16/2022 |
6.0.4 | 436 | 2/10/2022 |
6.0.3 | 416 | 2/9/2022 |
6.0.3-beta.9 | 135 | 2/10/2022 |
6.0.3-beta.7 | 149 | 1/27/2022 |
6.0.3-beta.6 | 150 | 1/19/2022 |
6.0.3-beta.5 | 142 | 1/17/2022 |
6.0.3-beta.4 | 147 | 1/16/2022 |
6.0.3-beta.3 | 142 | 1/14/2022 |
6.0.3-beta.2 | 154 | 1/13/2022 |
6.0.3-beta.1 | 173 | 1/11/2022 |
6.0.2 | 332 | 1/6/2022 |
6.0.1 | 969 | 12/3/2021 |
3.1.11 | 395 | 11/17/2021 |
3.1.10 | 1,796 | 7/29/2021 |
3.1.9 | 1,684 | 7/1/2021 |
3.1.8 | 1,647 | 12/15/2020 |
3.1.6 | 1,808 | 9/16/2020 |
3.1.5 | 1,685 | 9/8/2020 |