Skip to content

Commit

Permalink
bugfix delay remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Anson.G committed Oct 21, 2024
1 parent 02754e8 commit cec25c0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion FastCache.InMemory/Extension/DictExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ public static bool TryRemove<TKey, TValue>(this ConcurrentDictionary<TKey, TValu
var res = dictionary.TryRemove(key, out value);
if (res && seconds > 0)
{
Task.Delay(TimeSpan.FromSeconds(seconds)).ContinueWith(_ => { dictionary.TryRemove(key, out var _); });
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(seconds));
lock (dictionary)
{
dictionary.TryRemove(key, out var _);
}
});
}
return res;
}
Expand Down

0 comments on commit cec25c0

Please sign in to comment.