修复限流中间件编译错误:移除不存在的GetEntry方法调用,改用滑动窗口限流

This commit is contained in:
claw_bot 2026-03-12 03:10:16 +00:00
parent 34f9b623b2
commit 97efda4c2a

View File

@ -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);
}