Apply cache configuration
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | using Core.Blueprint.Caching.Configuration; | ||||||
| using Core.Blueprint.DAL.Mongo.Configuration; | using Core.Blueprint.DAL.Mongo.Configuration; | ||||||
| using Core.Blueprint.Logging.Configuration; | using Core.Blueprint.Logging.Configuration; | ||||||
| using Core.Thalos.Adapters.Extensions; | using Core.Thalos.Adapters.Extensions; | ||||||
| @@ -19,6 +20,7 @@ builder.Services.AddResponseCompression(); | |||||||
| builder.Services.AddProblemDetails(); | builder.Services.AddProblemDetails(); | ||||||
| builder.Services.AddMemoryCache(); | builder.Services.AddMemoryCache(); | ||||||
| builder.Services.AddLogs(builder); | builder.Services.AddLogs(builder); | ||||||
|  | builder.Services.AddRedis(builder.Configuration); | ||||||
| builder.Services.AddMongoLayer(builder.Configuration); | builder.Services.AddMongoLayer(builder.Configuration); | ||||||
| builder.Services.AddDALLayerServices(builder.Configuration); | builder.Services.AddDALLayerServices(builder.Configuration); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ | |||||||
|       "launchUrl": "swagger", |       "launchUrl": "swagger", | ||||||
|       "applicationUrl": "https://localhost:7031;http://localhost:5211", |       "applicationUrl": "https://localhost:7031;http://localhost:5211", | ||||||
|       "environmentVariables": { |       "environmentVariables": { | ||||||
|         "ASPNETCORE_ENVIRONMENT": "Development" |         "ASPNETCORE_ENVIRONMENT": "Local" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "IIS Express": { |     "IIS Express": { | ||||||
|   | |||||||
| @@ -6,17 +6,17 @@ | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   "AllowedHosts": "*", |   "AllowedHosts": "*", | ||||||
|   "MongoDbSettings": { |  | ||||||
|     "ConnectionString": "mongodb://localhost:27017", |  | ||||||
|     "Databasename": "Thalos", |  | ||||||
|     "Audience": "local-dev" |  | ||||||
|   }, |  | ||||||
|   "ConnectionStrings": { |   "ConnectionStrings": { | ||||||
|     "MongoDB": "mongodb://localhost:27017" |     "MongoDB": "mongodb://localhost:27017", | ||||||
|  |     "Redis": "localhost:6379" | ||||||
|   }, |   }, | ||||||
|   "MongoDb": { |   "MongoDb": { | ||||||
|     "DatabaseName": "Thalos", |     "DatabaseName": "Thalos", | ||||||
|     "LocalAudience": "local-dev" |     "LocalAudience": "" | ||||||
|   }, |   }, | ||||||
|   "DetailedErrors": true |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,7 +6,17 @@ | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   "AllowedHosts": "*", |   "AllowedHosts": "*", | ||||||
|   "Endpoints": { |   "ConnectionStrings": { | ||||||
|     "AppConfigurationURI": "https://sandbox-hci-usc-appcg.azconfig.io" |     "MongoDB": "mongodb://localhost:27017", | ||||||
|  |     "Redis": "localhost:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,8 +11,8 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Blueprint.Mongo" Version="0.0.5" /> |     <PackageReference Include="Blueprint.Mongo" Version="0.0.8" /> | ||||||
|     <PackageReference Include="Blueprint.Redis" Version="0.0.1" /> |     <PackageReference Include="Blueprint.Redis" Version="0.0.4" /> | ||||||
|     <PackageReference Include="BuildingBlocks.Library" Version="0.0.1" /> |     <PackageReference Include="BuildingBlocks.Library" Version="0.0.1" /> | ||||||
|     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> |     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   | |||||||
| @@ -5,13 +5,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | using Core.Blueprint.Caching; | ||||||
| using Core.Blueprint.Redis.Helpers; | using Core.Blueprint.Caching.Helpers; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Blueprint.Caching.Contracts; | ||||||
|  | using Core.Blueprint.Caching.Adapters; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -22,14 +24,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<ModuleAdapter> repository; |         private readonly CollectionRepository<ModuleAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         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 = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; |             this.cacheSettings = cacheSettings.Value; | ||||||
|             //this.cacheProvider = cacheProvider; |             this.cacheProvider = cacheProvider; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -56,13 +60,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken) |         public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id); |             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); |             var module = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|             //await cacheProvider.SetAsync(cacheKey, module); |             await cacheProvider.SetAsync(cacheKey, module); | ||||||
|  |  | ||||||
|             return module; |             return module; | ||||||
|         } |         } | ||||||
| @@ -75,13 +79,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken) |         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules"); |             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(); |             var modules = await repository.AsQueryable(); | ||||||
|  |  | ||||||
|             //await cacheProvider.SetAsync(cacheKey, modules); |             await cacheProvider.SetAsync(cacheKey, modules); | ||||||
|  |  | ||||||
|             return modules; |             return modules; | ||||||
|         } |         } | ||||||
| @@ -96,9 +100,9 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules); |             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 builder = Builders<ModuleAdapter>.Filter; | ||||||
|             var filters = new List<FilterDefinition<ModuleAdapter>>(); |             var filters = new List<FilterDefinition<ModuleAdapter>>(); | ||||||
| @@ -112,7 +116,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|  |  | ||||||
|             var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); |             var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||||
|  |  | ||||||
|             //await cacheProvider.SetAsync(cacheKey, modulesList); |             await cacheProvider.SetAsync(cacheKey, modulesList); | ||||||
|  |  | ||||||
|             return modulesList; |             return modulesList; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -5,8 +5,8 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | //using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | //using Core.Blueprint.Redis.Helpers; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| @@ -21,16 +21,17 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class PermissionProvider : IPermissionProvider |     public class PermissionProvider : IPermissionProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<PermissionAdapter> repository; |         private readonly CollectionRepository<PermissionAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         //private readonly CacheSettings cacheSettings; | ||||||
|         //private readonly IRedisCacheProvider cacheProvider; |         //private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public PermissionProvider(CollectionRepository<PermissionAdapter> repository, |         public PermissionProvider(CollectionRepository<PermissionAdapter> repository | ||||||
|         //IRedisCacheProvider cacheProvider,  |         //IRedisCacheProvider cacheProvider,  | ||||||
|         IOptions<CacheSettings> cacheSettings) |         //IOptions<CacheSettings> cacheSettings | ||||||
|  |             ) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; |             //this.cacheSettings = cacheSettings.Value; | ||||||
|             //this.cacheProvider = cacheProvider; |             //this.cacheProvider = cacheProvider; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ | |||||||
| using Core.Thalos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | //using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | //using Core.Blueprint.Redis.Helpers; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| @@ -27,16 +27,17 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class RoleProvider : IRoleProvider |     public class RoleProvider : IRoleProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<RoleAdapter> repository; |         private readonly CollectionRepository<RoleAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         //private readonly CacheSettings cacheSettings; | ||||||
|         //private readonly IRedisCacheProvider cacheProvider; |         //private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public RoleProvider(CollectionRepository<RoleAdapter> repository, |         public RoleProvider(CollectionRepository<RoleAdapter> repository | ||||||
|         //IRedisCacheProvider cacheProvider,  |         //IRedisCacheProvider cacheProvider,  | ||||||
|         IOptions<CacheSettings> cacheSettings) |         //IOptions<CacheSettings> cacheSettings | ||||||
|  |             ) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; |             //this.cacheSettings = cacheSettings.Value; | ||||||
|             //this.cacheProvider = cacheProvider; |             //this.cacheProvider = cacheProvider; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ | |||||||
| using Core.Thalos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | //using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | //using Core.Blueprint.Redis.Helpers; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| @@ -25,16 +25,17 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class UserProvider : IUserProvider |     public class UserProvider : IUserProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<UserAdapter> repository; |         private readonly CollectionRepository<UserAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         //private readonly CacheSettings cacheSettings; | ||||||
|         //private readonly IRedisCacheProvider cacheProvider; |         //private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public UserProvider(CollectionRepository<UserAdapter> repository, |         public UserProvider(CollectionRepository<UserAdapter> repository | ||||||
|         //IRedisCacheProvider cacheProvider,  |         //IRedisCacheProvider cacheProvider,  | ||||||
|         IOptions<CacheSettings> cacheSettings) |         //IOptions<CacheSettings> cacheSettings | ||||||
|  |             ) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; |             //this.cacheSettings = cacheSettings.Value; | ||||||
|             //this.cacheProvider = cacheProvider; |             //this.cacheProvider = cacheProvider; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Oscar Morales
					Oscar Morales