NetPro.ResponseCache 6.0.16

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                
#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                

ResponseCache使用

NuGet

支持对响应缓存,同样的查询条件在缓存时间内直接返回之前的响应接口,降低响应时间

使用

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 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.

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 192 7/24/2023
6.0.15 414 7/19/2022
6.0.14 437 7/10/2022
6.0.13 448 6/15/2022
6.0.12 437 6/15/2022
6.0.11 407 6/15/2022
6.0.10 408 6/11/2022
6.0.9 414 6/8/2022
6.0.8 417 5/26/2022
6.0.8-beta.3 131 5/24/2022
6.0.8-beta.2 119 5/24/2022
6.0.7 405 5/18/2022
6.0.6 434 4/28/2022
6.0.5 411 3/30/2022
6.0.5-beta.20 127 4/27/2022
6.0.5-beta.19 127 4/25/2022
6.0.5-beta.18 121 4/22/2022
6.0.5-beta.17 139 4/16/2022
6.0.5-beta.16 137 4/8/2022
6.0.5-beta.15 132 4/8/2022
6.0.5-beta.14 139 4/7/2022
6.0.5-beta.13 143 4/7/2022
6.0.5-beta.12 135 4/6/2022
6.0.5-beta.11 137 4/6/2022
6.0.5-beta.10 132 3/31/2022
6.0.5-beta.9 140 3/26/2022
6.0.5-beta.8 137 3/22/2022
6.0.5-beta.7 136 3/21/2022
6.0.5-beta.6 134 3/14/2022
6.0.5-beta.5 137 3/2/2022
6.0.5-beta.4 136 2/22/2022
6.0.5-beta.3 138 2/18/2022
6.0.5-beta.2 136 2/18/2022
6.0.5-beta.1 133 2/16/2022
6.0.4 432 2/10/2022
6.0.3 412 2/9/2022
6.0.3-beta.9 133 2/10/2022
6.0.3-beta.7 147 1/27/2022
6.0.3-beta.6 148 1/19/2022
6.0.3-beta.5 140 1/17/2022
6.0.3-beta.4 145 1/16/2022
6.0.3-beta.3 140 1/14/2022
6.0.3-beta.2 152 1/13/2022
6.0.3-beta.1 171 1/11/2022
6.0.2 328 1/6/2022
6.0.1 965 12/3/2021
3.1.11 391 11/17/2021
3.1.10 1,792 7/29/2021
3.1.9 1,680 7/1/2021
3.1.8 1,643 12/15/2020
3.1.6 1,804 9/16/2020
3.1.5 1,681 9/8/2020