Skip to content

Commit

Permalink
Merge pull request #24 from sj-distributor/Enhancement-Can-update-mem…
Browse files Browse the repository at this point in the history
…ory-cache

bugfix delay remove
  • Loading branch information
pygzfei authored Oct 21, 2024
2 parents 2d40751 + cec25c0 commit ffee204
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 ffee204

Please sign in to comment.