Add memory caching support in HistoryController
- Updated `EnvelopeGenerator.Extensions.csproj` to include `Microsoft.Extensions.Caching.Memory` package. - Refactored `HistoryController` to use `IMemoryCache` for caching functionality. - Replaced manual dictionary creation in `GetReferenceTypes` with a call to `GetEnumAsDictionary<ReferenceType>()`. - Changed enum type in `GetEnvelopeStatus` to `ReferenceType` for consistency. - Introduced `MemoryCacheExtensions` class with `GetEnumAsDictionary<TEnum>` method for efficient enum to dictionary conversion.
This commit is contained in:
21
EnvelopeGenerator.Extensions/MemoryCacheExtensions.cs
Normal file
21
EnvelopeGenerator.Extensions/MemoryCacheExtensions.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace EnvelopeGenerator.Extensions;
|
||||
|
||||
public static class MemoryCacheExtensions
|
||||
{
|
||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache)
|
||||
where TEnum : Enum
|
||||
{
|
||||
var referenceTypes = Enum.GetValues(typeof(TEnum))
|
||||
.Cast<TEnum>()
|
||||
.ToDictionary(rt =>
|
||||
{
|
||||
var key = rt.ToString();
|
||||
var keyAsCamelCase = char.ToLowerInvariant(key[0]) + key[1..];
|
||||
return keyAsCamelCase;
|
||||
}, rt => Convert.ToInt32(rt));
|
||||
|
||||
return referenceTypes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user