修复限流中间件编译错误:移除不存在的GetEntry方法调用,改用滑动窗口限流
This commit is contained in:
parent
34f9b623b2
commit
97efda4c2a
@ -54,14 +54,11 @@ public class RateLimitMiddleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 计数+1,首次访问设置过期时间
|
// 计数+1,首次访问设置过期时间
|
||||||
if (requestCount == 0)
|
var cacheEntryOptions = new MemoryCacheEntryOptions
|
||||||
{
|
{
|
||||||
_cache.Set(cacheKey, 1, TimeSpan.FromSeconds(WindowSeconds));
|
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(WindowSeconds)
|
||||||
}
|
};
|
||||||
else
|
_cache.Set(cacheKey, requestCount + 1, cacheEntryOptions);
|
||||||
{
|
|
||||||
_cache.Set(cacheKey, requestCount + 1, _cache.GetEntry(cacheKey).AbsoluteExpirationRelativeToNow ?? TimeSpan.FromSeconds(WindowSeconds));
|
|
||||||
}
|
|
||||||
|
|
||||||
await _next(context);
|
await _next(context);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user