Skip to content

Commit ffc8d35

Browse files
committed
Handles zero or negative expiration times
Ensures that ReplaceIfEqualAsync correctly handles cases where the expiresIn value is zero or negative by removing the key. This prevents potential issues related to invalid expiration settings.
1 parent 31948d8 commit ffc8d35

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Foundatio/Caching/InMemoryCacheClient.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
@@ -778,6 +778,12 @@ public async Task<bool> ReplaceIfEqualAsync<T>(string key, T value, T expected,
778778
{
779779
ArgumentException.ThrowIfNullOrEmpty(key);
780780

781+
if (expiresIn?.Ticks <= 0)
782+
{
783+
RemoveExpiredKey(key);
784+
return false;
785+
}
786+
781787
_logger.LogTrace("ReplaceIfEqualAsync Key: {Key} Expected: {Expected}", key, expected);
782788

783789
Interlocked.Increment(ref _writes);

0 commit comments

Comments
 (0)