From 64e0a4f74920e0534738f0037a6f800347dea91b Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 6 Mar 2026 11:41:47 +0100 Subject: [PATCH] Centralize cache key definitions in CacheKey class Refactored cache key usage by introducing a new static CacheKey class in the Application.Common namespace. Replaced the private DefaultConfigCacheId in ConfigService with CacheKey.DefaultConfig. Updated using statements accordingly. This change improves maintainability by centralizing cache key management and sets the stage for future cache key consolidation. --- EnvelopeGenerator.Application/Common/CacheKey.cs | 13 +++++++++++++ .../Services/ConfigService.cs | 5 ++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 EnvelopeGenerator.Application/Common/CacheKey.cs diff --git a/EnvelopeGenerator.Application/Common/CacheKey.cs b/EnvelopeGenerator.Application/Common/CacheKey.cs new file mode 100644 index 00000000..993564cf --- /dev/null +++ b/EnvelopeGenerator.Application/Common/CacheKey.cs @@ -0,0 +1,13 @@ +namespace EnvelopeGenerator.Application.Common; + +// TODO: merge other cache keys here as well, e.g. for templates, etc. +/// +/// +/// +public static class CacheKey +{ + /// + /// + /// + public static readonly Guid DefaultConfig = Guid.NewGuid(); +} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/ConfigService.cs b/EnvelopeGenerator.Application/Services/ConfigService.cs index 4b29fa6f..4d86781d 100644 --- a/EnvelopeGenerator.Application/Services/ConfigService.cs +++ b/EnvelopeGenerator.Application/Services/ConfigService.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using EnvelopeGenerator.Application.Common.Dto; using EnvelopeGenerator.Application.Common.Interfaces.Repositories; using EnvelopeGenerator.Application.Common.Interfaces.Services; +using EnvelopeGenerator.Application.Common; namespace EnvelopeGenerator.Application.Services; @@ -16,8 +17,6 @@ namespace EnvelopeGenerator.Application.Services; [Obsolete("Use MediatR")] public class ConfigService : ReadService, IConfigService { - private static readonly Guid DefaultConfigCacheId = Guid.NewGuid(); - private readonly IMemoryCache _cache; private readonly ILogger _logger; @@ -62,7 +61,7 @@ public class ConfigService : ReadService public async Task ReadDefaultAsync() { - var config = await _cache.GetOrCreateAsync(DefaultConfigCacheId, _ => ReadFirstAsync().ThenAsync( + var config = await _cache.GetOrCreateAsync(CacheKey.DefaultConfig, _ => ReadFirstAsync().ThenAsync( Success: config => config, Fail: (mssg, ntc) => {