-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: refactoring and various improvements (#848)
Co-authored-by: kjetilhau <[email protected]>
- Loading branch information
Showing
25 changed files
with
128 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
backend/src/Equinor.ProjectExecutionPortal.Application/Cache/CacheOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Equinor.ProjectExecutionPortal.Application.Cache; | ||
|
||
public class CacheOptions | ||
{ | ||
public int FusionAppsCacheMinutes { get; init; } | ||
} |
21 changes: 11 additions & 10 deletions
21
backend/src/Equinor.ProjectExecutionPortal.Application/Cache/FusionAppsCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
using Fusion.Integration.Apps.Abstractions.Abstractions; | ||
using Fusion.Integration.Apps.Abstractions.Models; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Equinor.ProjectExecutionPortal.Application.Cache; | ||
|
||
public class FusionAppsCache : IFusionAppsCache | ||
{ | ||
private readonly ICacheManager _cacheManager; | ||
private readonly IAppsClient _fusionAppsClient; | ||
private readonly IOptions<CacheOptions> _cacheOptions; | ||
|
||
public FusionAppsCache(ICacheManager cacheManager, IAppsClient fusionAppsClient) | ||
private const string FusionAppCacheKey = "FUSION_APP"; | ||
|
||
public FusionAppsCache(ICacheManager cacheManager, IAppsClient fusionAppsClient, IOptions<CacheOptions> cacheOptions) | ||
{ | ||
_cacheManager = cacheManager; | ||
_fusionAppsClient = fusionAppsClient; | ||
_cacheOptions = cacheOptions; | ||
} | ||
|
||
// TODO: Move cache duration to app settings | ||
|
||
public async Task<List<App>> GetFusionApps() | ||
{ | ||
return await _cacheManager.GetOrCreateAsync("FUSION_APP", | ||
return await _cacheManager.GetOrCreateAsync(FusionAppCacheKey, | ||
async () => | ||
{ | ||
var fusionApps = await _fusionAppsClient.GetAppsAsync(); | ||
|
||
return fusionApps.ToList(); | ||
}, | ||
CacheDuration.Minutes, | ||
60); | ||
CacheDuration.Minutes, _cacheOptions.Value.FusionAppsCacheMinutes); | ||
} | ||
|
||
public async Task<App?> GetFusionApp(string appKey) | ||
{ | ||
return await _cacheManager.GetOrCreateAsync("FUSION_APP", | ||
return await _cacheManager.GetOrCreateAsync(FusionAppCacheKey, | ||
async () => await _fusionAppsClient.GetAppAsync(appKey), | ||
CacheDuration.Minutes, | ||
60); | ||
CacheDuration.Minutes, _cacheOptions.Value.FusionAppsCacheMinutes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.