diff --git a/src/AspNetCoreRateLimit/Store/DistributedCacheRateLimitStore.cs b/src/AspNetCoreRateLimit/Store/DistributedCacheRateLimitStore.cs index 6ea6683c..c2f5d005 100644 --- a/src/AspNetCoreRateLimit/Store/DistributedCacheRateLimitStore.cs +++ b/src/AspNetCoreRateLimit/Store/DistributedCacheRateLimitStore.cs @@ -17,10 +17,14 @@ public DistributedCacheRateLimitStore(IDistributedCache cache) public Task SetAsync(string id, T entry, TimeSpan? expirationTime = null, CancellationToken cancellationToken = default) { - return _cache.SetStringAsync(id, - JsonConvert.SerializeObject(entry), - expirationTime.HasValue ? new DistributedCacheEntryOptions().SetAbsoluteExpiration(expirationTime.Value) : null, - cancellationToken); + var options = new DistributedCacheEntryOptions(); + + if (expirationTime.HasValue) + { + options.SetAbsoluteExpiration(expirationTime.Value); + } + + return _cache.SetStringAsync(id, JsonConvert.SerializeObject(entry), options, cancellationToken); } public async Task ExistsAsync(string id, CancellationToken cancellationToken = default) diff --git a/src/AspNetCoreRateLimit/Store/MemoryCacheRateLimitStore.cs b/src/AspNetCoreRateLimit/Store/MemoryCacheRateLimitStore.cs index 619c14db..46e3ed5c 100644 --- a/src/AspNetCoreRateLimit/Store/MemoryCacheRateLimitStore.cs +++ b/src/AspNetCoreRateLimit/Store/MemoryCacheRateLimitStore.cs @@ -38,7 +38,7 @@ public Task RemoveAsync(string id, CancellationToken cancellationToken = default public Task SetAsync(string id, T entry, TimeSpan? expirationTime = null, CancellationToken cancellationToken = default) { - MemoryCacheEntryOptions options = new MemoryCacheEntryOptions + var options = new MemoryCacheEntryOptions { Priority = CacheItemPriority.NeverRemove };