Skip to content

Commit

Permalink
misc: log which key is throwing from the guarded memory cache
Browse files Browse the repository at this point in the history
  • Loading branch information
revam authored Sep 14, 2024
1 parent cad46bb commit 32ea3fe
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Shokofin/Utils/GuardedMemoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public TItem GetOrCreate<TItem>(object key, Action<TItem> foundAction, Func<TIte

throw;
}
catch (Exception ex) {
Logger.LogWarning(ex, "Got an unexpected exception for key: {Key}", key);
throw;
}
}

public async Task<TItem> GetOrCreateAsync<TItem>(object key, Action<TItem> foundAction, Func<Task<TItem>> createFactory, MemoryCacheEntryOptions? createOptions = null)
Expand Down Expand Up @@ -122,6 +126,10 @@ public async Task<TItem> GetOrCreateAsync<TItem>(object key, Action<TItem> found

throw;
}
catch (Exception ex) {
Logger.LogWarning(ex, "Got an unexpected exception for key: {Key}", key);
throw;
}
}

public TItem GetOrCreate<TItem>(object key, Func<TItem> createFactory, MemoryCacheEntryOptions? createOptions = null)
Expand Down Expand Up @@ -159,6 +167,10 @@ public TItem GetOrCreate<TItem>(object key, Func<TItem> createFactory, MemoryCac

throw;
}
catch (Exception ex) {
Logger.LogWarning(ex, "Got an unexpected exception for key: {Key}", key);
throw;
}
}

public async Task<TItem> GetOrCreateAsync<TItem>(object key, Func<Task<TItem>> createFactory, MemoryCacheEntryOptions? createOptions = null)
Expand Down Expand Up @@ -196,6 +208,10 @@ public async Task<TItem> GetOrCreateAsync<TItem>(object key, Func<Task<TItem>> c

throw;
}
catch (Exception ex) {
Logger.LogWarning(ex, "Got an unexpected exception for key: {Key}", key);
throw;
}
}

public void Dispose()
Expand All @@ -218,4 +234,4 @@ public bool TryGetValue<TItem>(object key, [NotNullWhen(true)] out TItem? value)

public TItem? Set<TItem>(object key, [NotNullIfNotNull(nameof(value))] TItem? value, MemoryCacheEntryOptions? createOptions = null)
=> Cache.Set(key, value, createOptions ?? CacheEntryOptions);
}
}

0 comments on commit 32ea3fe

Please sign in to comment.