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 156 7/24/2023
6.0.15 395 7/19/2022
6.0.14 410 7/10/2022
6.0.13 419 6/15/2022
6.0.12 404 6/15/2022
6.0.11 375 6/15/2022
6.0.10 384 6/11/2022
6.0.9 384 6/8/2022
6.0.8 384 5/26/2022
6.0.8-beta.3 112 5/24/2022
6.0.8-beta.2 108 5/24/2022
6.0.7 392 5/18/2022
6.0.6 403 4/28/2022
6.0.5 380 3/30/2022
6.0.5-beta.20 114 4/27/2022
6.0.5-beta.19 109 4/25/2022
6.0.5-beta.18 106 4/22/2022
6.0.5-beta.17 118 4/16/2022
6.0.5-beta.16 121 4/8/2022
6.0.5-beta.15 122 4/8/2022
6.0.5-beta.14 122 4/7/2022
6.0.5-beta.13 125 4/7/2022
6.0.5-beta.12 118 4/6/2022
6.0.5-beta.11 120 4/6/2022
6.0.5-beta.10 114 3/31/2022
6.0.5-beta.9 122 3/26/2022
6.0.5-beta.8 120 3/22/2022
6.0.5-beta.7 118 3/21/2022
6.0.5-beta.6 118 3/14/2022
6.0.5-beta.5 118 3/2/2022
6.0.5-beta.4 119 2/22/2022
6.0.5-beta.3 123 2/18/2022
6.0.5-beta.2 119 2/18/2022
6.0.5-beta.1 122 2/16/2022
6.0.4 402 2/10/2022
6.0.3 400 2/9/2022
6.0.3-beta.9 123 2/10/2022
6.0.3-beta.7 131 1/27/2022
6.0.3-beta.6 131 1/19/2022
6.0.3-beta.5 124 1/17/2022
6.0.3-beta.4 131 1/16/2022
6.0.3-beta.3 124 1/14/2022
6.0.3-beta.2 137 1/13/2022
6.0.3-beta.1 155 1/11/2022
6.0.2 298 1/6/2022
6.0.1 936 12/3/2021
3.1.11 361 11/17/2021
3.1.10 1,733 7/29/2021
3.1.9 1,618 7/1/2021
3.1.8 1,587 12/15/2020
3.1.6 1,743 9/16/2020
3.1.5 1,624 9/8/2020