Skip to content

Commit

Permalink
added activity
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelNygren-Norce committed Nov 22, 2024
1 parent 9451786 commit 7168cba
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions HzMemoryCache/HzMemoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public IList<T> GetOrSetBatch<T>(IList<string> keys, Func<IList<string>, List<Ke

public IList<T> GetOrSetBatch<T>(IList<string> keys, Func<IList<string>, List<KeyValuePair<string, T>>> valueFactory, TimeSpan ttl)
{
using var activity = Activities.Source.StartActivityWithCommonTags(Activities.Names.GetOrSetBatch, Activities.Area.HzMemoryCache, key: string.Join(",",keys??new List<string>()));


var cachedItems = keys.Select(key => new KeyValuePair<string, T?>(key, Get<T>(key)));
var missingKeys = cachedItems.Where(kvp => IsNullOrDefault(kvp.Value)).Select(kvp => kvp.Key).ToList();
var factoryRetrievedItems = valueFactory(missingKeys).ToDictionary(kv => kv.Key, kv => kv.Value);
Expand Down

0 comments on commit 7168cba

Please sign in to comment.