Enhance MemoryCacheExtensions and update HistoryController
- Modified `GetEnumAsDictionary` to accept a key and ignores for better caching and filtering of enum values. - Updated XML documentation in `HistoryController.cs` to correct status code descriptions. - Adjusted `GetEnvelopeStatus` to use the new parameters for improved control over cached enum values.
This commit is contained in:
@@ -6,11 +6,15 @@ public static class MemoryCacheExtensions
|
||||
{
|
||||
private static readonly Guid BaseId = Guid.NewGuid();
|
||||
|
||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache)
|
||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache, string key = "", params IEnumerable<TEnum>[] ignores)
|
||||
where TEnum : Enum
|
||||
=> memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName, _ =>
|
||||
Enum.GetValues(typeof(TEnum))
|
||||
=> memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName + key, _ =>
|
||||
{
|
||||
List<TEnum> mergedIgnores = ignores.SelectMany(x => x).ToList();
|
||||
return Enum.GetValues(typeof(TEnum))
|
||||
.Cast<TEnum>()
|
||||
.ToDictionary(e => e.ToString(), e => Convert.ToInt32(e)))
|
||||
.Where(e => !mergedIgnores.Contains(e))
|
||||
.ToDictionary(e => e.ToString(), e => Convert.ToInt32(e));
|
||||
})
|
||||
?? throw new InvalidOperationException($"Failed to cache or retrieve enum dictionary for type '{typeof(TEnum).FullName}'.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user