We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4384b90 commit 566bd3cCopy full SHA for 566bd3c
StringExtensions/CacheExtensions.cs
@@ -16,12 +16,26 @@ public static Task<T> AtomicGetOrCreateAsync<T>(
16
string key,
17
Func<ICacheEntry, Task<T>> factory)
18
{
19
- lock (lockObject)
+ return cache.GetOrCreate<Task<T>>(key, (entry) =>
20
21
- return cache.GetOrCreate<Task<T>>(key, (entry) => {
22
- return factory(entry);
23
- });
24
- }
+ lock (lockObject)
+ {
+ Func<ICacheEntry, Task<T>> fx = async (e2) => {
+ try {
25
+ return await factory(e2);
26
+ } catch
27
28
+ // it is stale...
29
+ cache.Remove(key);
30
+ throw;
31
+ }
32
+ };
33
+ return cache.GetOrCreate<Task<T>>(key, (e1) =>
34
35
+ return fx(e1);
36
+ });
37
38
39
}
40
41
0 commit comments