Apply cache configuration

This commit is contained in:
Oscar Morales
2025-06-06 10:22:07 -06:00
parent f5b5f7d0f0
commit 8207048c25
9 changed files with 64 additions and 45 deletions

View File

@@ -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);

View File

@@ -26,7 +26,7 @@
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7031;http://localhost:5211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Local"
}
},
"IIS Express": {

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -11,8 +11,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Blueprint.Mongo" Version="0.0.5" />
<PackageReference Include="Blueprint.Redis" Version="0.0.1" />
<PackageReference Include="Blueprint.Mongo" Version="0.0.8" />
<PackageReference Include="Blueprint.Redis" Version="0.0.4" />
<PackageReference Include="BuildingBlocks.Library" Version="0.0.1" />
<PackageReference Include="Mapster" Version="7.4.2-pre02" />
</ItemGroup>

View File

@@ -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<ModuleAdapter> repository;
private readonly CacheSettings cacheSettings;
//private readonly IRedisCacheProvider cacheProvider;
private readonly ICacheProvider cacheProvider;
public ModuleProvider(CollectionRepository<ModuleAdapter> repository, IOptions<CacheSettings> cacheSettings)
public ModuleProvider(CollectionRepository<ModuleAdapter> repository,
ICacheProvider cacheProvider,
IOptions<CacheSettings> cacheSettings)
{
this.repository = repository;
this.repository.CollectionInitialization();
this.cacheSettings = cacheSettings.Value;
//this.cacheProvider = cacheProvider;
this.cacheProvider = cacheProvider;
}
/// <summary>
@@ -56,13 +60,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding
public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken)
{
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id);
//var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(cacheKey);
var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(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<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken)
{
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules");
//var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? [];
var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(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<IEnumerable<ModuleAdapter>>(cacheKey) ?? [];
var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? [];
//if (cachedData.Any()) return cachedData;
if (cachedData.Any()) return cachedData;
var builder = Builders<ModuleAdapter>.Filter;
var filters = new List<FilterDefinition<ModuleAdapter>>();
@@ -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;
}

View File

@@ -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<PermissionAdapter> repository;
private readonly CacheSettings cacheSettings;
//private readonly CacheSettings cacheSettings;
//private readonly IRedisCacheProvider cacheProvider;
public PermissionProvider(CollectionRepository<PermissionAdapter> repository,
public PermissionProvider(CollectionRepository<PermissionAdapter> repository
//IRedisCacheProvider cacheProvider,
IOptions<CacheSettings> cacheSettings)
//IOptions<CacheSettings> cacheSettings
)
{
this.repository = repository;
this.repository.CollectionInitialization();
this.cacheSettings = cacheSettings.Value;
//this.cacheSettings = cacheSettings.Value;
//this.cacheProvider = cacheProvider;
}

View File

@@ -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<RoleAdapter> repository;
private readonly CacheSettings cacheSettings;
//private readonly CacheSettings cacheSettings;
//private readonly IRedisCacheProvider cacheProvider;
public RoleProvider(CollectionRepository<RoleAdapter> repository,
public RoleProvider(CollectionRepository<RoleAdapter> repository
//IRedisCacheProvider cacheProvider,
IOptions<CacheSettings> cacheSettings)
//IOptions<CacheSettings> cacheSettings
)
{
this.repository = repository;
this.repository.CollectionInitialization();
this.cacheSettings = cacheSettings.Value;
//this.cacheSettings = cacheSettings.Value;
//this.cacheProvider = cacheProvider;
}

View File

@@ -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<UserAdapter> repository;
private readonly CacheSettings cacheSettings;
//private readonly CacheSettings cacheSettings;
//private readonly IRedisCacheProvider cacheProvider;
public UserProvider(CollectionRepository<UserAdapter> repository,
public UserProvider(CollectionRepository<UserAdapter> repository
//IRedisCacheProvider cacheProvider,
IOptions<CacheSettings> cacheSettings)
//IOptions<CacheSettings> cacheSettings
)
{
this.repository = repository;
this.repository.CollectionInitialization();
this.cacheSettings = cacheSettings.Value;
//this.cacheSettings = cacheSettings.Value;
//this.cacheProvider = cacheProvider;
}