From 97efda4c2ab5086de9d6348e684b759056d98ad7 Mon Sep 17 00:00:00 2001 From: claw_bot Date: Thu, 12 Mar 2026 03:10:16 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=99=90=E6=B5=81=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E4=BB=B6=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF=EF=BC=9A?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84GetEntry?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=B0=83=E7=94=A8=EF=BC=8C=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E7=AA=97=E5=8F=A3=E9=99=90=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AssetManager.API/Middleware/RateLimitMiddleware.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/AssetManager.API/Middleware/RateLimitMiddleware.cs b/AssetManager.API/Middleware/RateLimitMiddleware.cs index e33e7f2..cc80b47 100644 --- a/AssetManager.API/Middleware/RateLimitMiddleware.cs +++ b/AssetManager.API/Middleware/RateLimitMiddleware.cs @@ -54,14 +54,11 @@ public class RateLimitMiddleware } // 计数+1,首次访问设置过期时间 - if (requestCount == 0) + var cacheEntryOptions = new MemoryCacheEntryOptions { - _cache.Set(cacheKey, 1, TimeSpan.FromSeconds(WindowSeconds)); - } - else - { - _cache.Set(cacheKey, requestCount + 1, _cache.GetEntry(cacheKey).AbsoluteExpirationRelativeToNow ?? TimeSpan.FromSeconds(WindowSeconds)); - } + AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(WindowSeconds) + }; + _cache.Set(cacheKey, requestCount + 1, cacheEntryOptions); await _next(context); }