NetPro.ResponseCache
6.0.5-beta.2
.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.
This is a prerelease version of NetPro.ResponseCache.
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 NetPro.ResponseCache --version 6.0.5-beta.2
NuGet\Install-Package NetPro.ResponseCache -Version 6.0.5-beta.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="NetPro.ResponseCache" Version="6.0.5-beta.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.ResponseCache --version 6.0.5-beta.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.ResponseCache, 6.0.5-beta.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.
// Install NetPro.ResponseCache as a Cake Addin #addin nuget:?package=NetPro.ResponseCache&version=6.0.5-beta.2&prerelease // Install NetPro.ResponseCache as a Cake Tool #tool nuget:?package=NetPro.ResponseCache&version=6.0.5-beta.2&prerelease
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.5-beta.2)
- NetPro.NetProShareRequestBody (>= 6.0.5-beta.2)
-
net6.0
- NetPro.CsRedis (>= 6.0.5-beta.2)
- NetPro.NetProShareRequestBody (>= 6.0.5-beta.2)
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 | 189 | 7/24/2023 |
6.0.15 | 411 | 7/19/2022 |
6.0.14 | 434 | 7/10/2022 |
6.0.13 | 445 | 6/15/2022 |
6.0.12 | 434 | 6/15/2022 |
6.0.11 | 404 | 6/15/2022 |
6.0.10 | 405 | 6/11/2022 |
6.0.9 | 409 | 6/8/2022 |
6.0.8 | 414 | 5/26/2022 |
6.0.8-beta.3 | 130 | 5/24/2022 |
6.0.8-beta.2 | 118 | 5/24/2022 |
6.0.7 | 402 | 5/18/2022 |
6.0.6 | 431 | 4/28/2022 |
6.0.5 | 406 | 3/30/2022 |
6.0.5-beta.20 | 124 | 4/27/2022 |
6.0.5-beta.19 | 126 | 4/25/2022 |
6.0.5-beta.18 | 120 | 4/22/2022 |
6.0.5-beta.17 | 138 | 4/16/2022 |
6.0.5-beta.16 | 136 | 4/8/2022 |
6.0.5-beta.15 | 131 | 4/8/2022 |
6.0.5-beta.14 | 138 | 4/7/2022 |
6.0.5-beta.13 | 142 | 4/7/2022 |
6.0.5-beta.12 | 134 | 4/6/2022 |
6.0.5-beta.11 | 136 | 4/6/2022 |
6.0.5-beta.10 | 131 | 3/31/2022 |
6.0.5-beta.9 | 139 | 3/26/2022 |
6.0.5-beta.8 | 136 | 3/22/2022 |
6.0.5-beta.7 | 135 | 3/21/2022 |
6.0.5-beta.6 | 133 | 3/14/2022 |
6.0.5-beta.5 | 136 | 3/2/2022 |
6.0.5-beta.4 | 133 | 2/22/2022 |
6.0.5-beta.3 | 137 | 2/18/2022 |
6.0.5-beta.2 | 135 | 2/18/2022 |
6.0.5-beta.1 | 132 | 2/16/2022 |
6.0.4 | 427 | 2/10/2022 |
6.0.3 | 409 | 2/9/2022 |
6.0.3-beta.9 | 132 | 2/10/2022 |
6.0.3-beta.7 | 144 | 1/27/2022 |
6.0.3-beta.6 | 147 | 1/19/2022 |
6.0.3-beta.5 | 139 | 1/17/2022 |
6.0.3-beta.4 | 144 | 1/16/2022 |
6.0.3-beta.3 | 139 | 1/14/2022 |
6.0.3-beta.2 | 151 | 1/13/2022 |
6.0.3-beta.1 | 170 | 1/11/2022 |
6.0.2 | 325 | 1/6/2022 |
6.0.1 | 962 | 12/3/2021 |
3.1.11 | 388 | 11/17/2021 |
3.1.10 | 1,789 | 7/29/2021 |
3.1.9 | 1,677 | 7/1/2021 |
3.1.8 | 1,640 | 12/15/2020 |
3.1.6 | 1,801 | 9/16/2020 |
3.1.5 | 1,676 | 9/8/2020 |