From 8207048c25c872f92a5eef4f52f8b501982a969d Mon Sep 17 00:00:00 2001 From: Oscar Morales Date: Fri, 6 Jun 2025 10:22:07 -0600 Subject: [PATCH] Apply cache configuration --- Core.Thalos.DAL.API/Program.cs | 2 ++ .../Properties/launchSettings.json | 2 +- .../appsettings.Development.json | 16 +++++----- Core.Thalos.DAL.API/appsettings.json | 14 ++++++-- .../Core.Thalos.Provider.csproj | 4 +-- .../Providers/Onboarding/ModuleProvider.cs | 32 +++++++++++-------- .../Onboarding/PermissionProvider.cs | 13 ++++---- .../Providers/Onboarding/RoleProvider.cs | 13 ++++---- .../Providers/Onboarding/UserProvider.cs | 13 ++++---- 9 files changed, 64 insertions(+), 45 deletions(-) diff --git a/Core.Thalos.DAL.API/Program.cs b/Core.Thalos.DAL.API/Program.cs index fd55259..40eacb0 100644 --- a/Core.Thalos.DAL.API/Program.cs +++ b/Core.Thalos.DAL.API/Program.cs @@ -1,3 +1,4 @@ +using Core.Blueprint.Caching.Configuration; using Core.Blueprint.DAL.Mongo.Configuration; using Core.Blueprint.Logging.Configuration; using Core.Thalos.Adapters.Extensions; @@ -19,6 +20,7 @@ builder.Services.AddResponseCompression(); builder.Services.AddProblemDetails(); builder.Services.AddMemoryCache(); builder.Services.AddLogs(builder); +builder.Services.AddRedis(builder.Configuration); builder.Services.AddMongoLayer(builder.Configuration); builder.Services.AddDALLayerServices(builder.Configuration); diff --git a/Core.Thalos.DAL.API/Properties/launchSettings.json b/Core.Thalos.DAL.API/Properties/launchSettings.json index 105edd9..2deec93 100644 --- a/Core.Thalos.DAL.API/Properties/launchSettings.json +++ b/Core.Thalos.DAL.API/Properties/launchSettings.json @@ -26,7 +26,7 @@ "launchUrl": "swagger", "applicationUrl": "https://localhost:7031;http://localhost:5211", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Local" } }, "IIS Express": { diff --git a/Core.Thalos.DAL.API/appsettings.Development.json b/Core.Thalos.DAL.API/appsettings.Development.json index 2f19a3c..66f27d7 100644 --- a/Core.Thalos.DAL.API/appsettings.Development.json +++ b/Core.Thalos.DAL.API/appsettings.Development.json @@ -6,17 +6,17 @@ } }, "AllowedHosts": "*", - "MongoDbSettings": { - "ConnectionString": "mongodb://localhost:27017", - "Databasename": "Thalos", - "Audience": "local-dev" - }, "ConnectionStrings": { - "MongoDB": "mongodb://localhost:27017" + "MongoDB": "mongodb://localhost:27017", + "Redis": "localhost:6379" }, "MongoDb": { "DatabaseName": "Thalos", - "LocalAudience": "local-dev" + "LocalAudience": "" }, - "DetailedErrors": true + "DetailedErrors": true, + "UseRedisCache": true, + "CacheSettings": { + "DefaultCacheDurationInMinutes": 3 + } } diff --git a/Core.Thalos.DAL.API/appsettings.json b/Core.Thalos.DAL.API/appsettings.json index d321977..66f27d7 100644 --- a/Core.Thalos.DAL.API/appsettings.json +++ b/Core.Thalos.DAL.API/appsettings.json @@ -6,7 +6,17 @@ } }, "AllowedHosts": "*", - "Endpoints": { - "AppConfigurationURI": "https://sandbox-hci-usc-appcg.azconfig.io" + "ConnectionStrings": { + "MongoDB": "mongodb://localhost:27017", + "Redis": "localhost:6379" + }, + "MongoDb": { + "DatabaseName": "Thalos", + "LocalAudience": "" + }, + "DetailedErrors": true, + "UseRedisCache": true, + "CacheSettings": { + "DefaultCacheDurationInMinutes": 3 } } diff --git a/Core.Thalos.Provider/Core.Thalos.Provider.csproj b/Core.Thalos.Provider/Core.Thalos.Provider.csproj index cfe33f6..f2a69fe 100644 --- a/Core.Thalos.Provider/Core.Thalos.Provider.csproj +++ b/Core.Thalos.Provider/Core.Thalos.Provider.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs index a895c44..fa8e248 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs @@ -5,13 +5,15 @@ // *********************************************************************** using Core.Thalos.Adapters; using Core.Blueprint.Mongo; -using Core.Blueprint.Redis; -using Core.Blueprint.Redis.Helpers; +using Core.Blueprint.Caching; +using Core.Blueprint.Caching.Helpers; using Mapster; using Microsoft.Extensions.Options; using MongoDB.Driver; using Core.Thalos.Provider.Contracts; using Core.Thalos.Domain.Contexts.Onboarding.Request; +using Core.Blueprint.Caching.Contracts; +using Core.Blueprint.Caching.Adapters; namespace Core.Thalos.Provider.Providers.Onboarding { @@ -22,14 +24,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding { private readonly CollectionRepository repository; private readonly CacheSettings cacheSettings; - //private readonly IRedisCacheProvider cacheProvider; + private readonly ICacheProvider cacheProvider; - public ModuleProvider(CollectionRepository repository, IOptions cacheSettings) + public ModuleProvider(CollectionRepository repository, + ICacheProvider cacheProvider, + IOptions cacheSettings) { this.repository = repository; this.repository.CollectionInitialization(); this.cacheSettings = cacheSettings.Value; - //this.cacheProvider = cacheProvider; + this.cacheProvider = cacheProvider; } /// @@ -56,13 +60,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding public async ValueTask GetModuleById(string _id, CancellationToken cancellationToken) { var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id); - //var cachedData = await cacheProvider.GetAsync(cacheKey); + var cachedData = await cacheProvider.GetAsync(cacheKey); - //if (cachedData is not null) { return cachedData; } + if (cachedData is not null) { return cachedData; } var module = await repository.FindByIdAsync(_id); - //await cacheProvider.SetAsync(cacheKey, module); + await cacheProvider.SetAsync(cacheKey, module); return module; } @@ -75,13 +79,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding public async ValueTask> GetAllModules(CancellationToken cancellationToken) { var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules"); - //var cachedData = await cacheProvider.GetAsync>(cacheKey) ?? []; + var cachedData = await cacheProvider.GetAsync>(cacheKey) ?? []; - //if (cachedData.Any()) return cachedData; + if (cachedData.Any()) return cachedData; var modules = await repository.AsQueryable(); - //await cacheProvider.SetAsync(cacheKey, modules); + await cacheProvider.SetAsync(cacheKey, modules); return modules; } @@ -96,9 +100,9 @@ namespace Core.Thalos.Provider.Providers.Onboarding { var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules); - //var cachedData = await cacheProvider.GetAsync>(cacheKey) ?? []; + var cachedData = await cacheProvider.GetAsync>(cacheKey) ?? []; - //if (cachedData.Any()) return cachedData; + if (cachedData.Any()) return cachedData; var builder = Builders.Filter; var filters = new List>(); @@ -112,7 +116,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); - //await cacheProvider.SetAsync(cacheKey, modulesList); + await cacheProvider.SetAsync(cacheKey, modulesList); return modulesList; } diff --git a/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs index e2bf7d5..e2c1421 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs @@ -5,8 +5,8 @@ // *********************************************************************** using Core.Thalos.Adapters; using Core.Blueprint.Mongo; -using Core.Blueprint.Redis; -using Core.Blueprint.Redis.Helpers; +//using Core.Blueprint.Redis; +//using Core.Blueprint.Redis.Helpers; using Mapster; using Microsoft.Extensions.Options; using MongoDB.Driver; @@ -21,16 +21,17 @@ namespace Core.Thalos.Provider.Providers.Onboarding public class PermissionProvider : IPermissionProvider { private readonly CollectionRepository repository; - private readonly CacheSettings cacheSettings; + //private readonly CacheSettings cacheSettings; //private readonly IRedisCacheProvider cacheProvider; - public PermissionProvider(CollectionRepository repository, + public PermissionProvider(CollectionRepository repository //IRedisCacheProvider cacheProvider, - IOptions cacheSettings) + //IOptions cacheSettings + ) { this.repository = repository; this.repository.CollectionInitialization(); - this.cacheSettings = cacheSettings.Value; + //this.cacheSettings = cacheSettings.Value; //this.cacheProvider = cacheProvider; } diff --git a/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs index 727c4ab..ac58137 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs @@ -6,8 +6,8 @@ using Core.Thalos.Adapters; using Core.Thalos.Adapters.Common.Enums; using Core.Blueprint.Mongo; -using Core.Blueprint.Redis; -using Core.Blueprint.Redis.Helpers; +//using Core.Blueprint.Redis; +//using Core.Blueprint.Redis.Helpers; using Mapster; using Microsoft.Extensions.Options; using MongoDB.Driver; @@ -27,16 +27,17 @@ namespace Core.Thalos.Provider.Providers.Onboarding public class RoleProvider : IRoleProvider { private readonly CollectionRepository repository; - private readonly CacheSettings cacheSettings; + //private readonly CacheSettings cacheSettings; //private readonly IRedisCacheProvider cacheProvider; - public RoleProvider(CollectionRepository repository, + public RoleProvider(CollectionRepository repository //IRedisCacheProvider cacheProvider, - IOptions cacheSettings) + //IOptions cacheSettings + ) { this.repository = repository; this.repository.CollectionInitialization(); - this.cacheSettings = cacheSettings.Value; + //this.cacheSettings = cacheSettings.Value; //this.cacheProvider = cacheProvider; } diff --git a/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs index 706e05b..705a2d6 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs @@ -7,8 +7,8 @@ using Core.Thalos.Adapters; using Core.Thalos.Adapters.Common.Enums; using Core.Blueprint.Mongo; -using Core.Blueprint.Redis; -using Core.Blueprint.Redis.Helpers; +//using Core.Blueprint.Redis; +//using Core.Blueprint.Redis.Helpers; using Mapster; using Microsoft.Extensions.Options; using MongoDB.Driver; @@ -25,16 +25,17 @@ namespace Core.Thalos.Provider.Providers.Onboarding public class UserProvider : IUserProvider { private readonly CollectionRepository repository; - private readonly CacheSettings cacheSettings; + //private readonly CacheSettings cacheSettings; //private readonly IRedisCacheProvider cacheProvider; - public UserProvider(CollectionRepository repository, + public UserProvider(CollectionRepository repository //IRedisCacheProvider cacheProvider, - IOptions cacheSettings) + //IOptions cacheSettings + ) { this.repository = repository; this.repository.CollectionInitialization(); - this.cacheSettings = cacheSettings.Value; + //this.cacheSettings = cacheSettings.Value; //this.cacheProvider = cacheProvider; }