diff --git a/src/App/Abstractions/Services/IAppSettingsService.cs b/src/App/Abstractions/Services/IAppSettingsService.cs index 1cd80ff54..c37d604a4 100644 --- a/src/App/Abstractions/Services/IAppSettingsService.cs +++ b/src/App/Abstractions/Services/IAppSettingsService.cs @@ -17,5 +17,6 @@ namespace Bit.App.Abstractions string ApiUrl { get; set; } string IdentityUrl { get; set; } string IconsUrl { get; set; } + bool ClearCiphersCache { get; set; } } } \ No newline at end of file diff --git a/src/App/Constants.cs b/src/App/Constants.cs index b5751c5d7..96f038a92 100644 --- a/src/App/Constants.cs +++ b/src/App/Constants.cs @@ -46,6 +46,7 @@ public const string IdentityUrl = "other:identityUrl"; public const string IconsUrl = "other:iconsUrl"; public const string FailedPinAttempts = "other:failedPinAttempts"; + public const string ClearCiphersCache = "other:clearCiphersCache"; public const int SelectFileRequestCode = 42; public const int SelectFilePermissionRequestCode = 43; diff --git a/src/App/Services/AppSettingsService.cs b/src/App/Services/AppSettingsService.cs index 68a9d18a6..a24052261 100644 --- a/src/App/Services/AppSettingsService.cs +++ b/src/App/Services/AppSettingsService.cs @@ -196,5 +196,17 @@ namespace Bit.App.Services _settings.AddOrUpdateValue(Constants.IconsUrl, value); } } + + public bool ClearCiphersCache + { + get + { + return _settings.GetValueOrDefault(Constants.ClearCiphersCache, false); + } + set + { + _settings.AddOrUpdateValue(Constants.ClearCiphersCache, value); + } + } } } diff --git a/src/App/Services/CipherService.cs b/src/App/Services/CipherService.cs index f31a85905..87399d71f 100644 --- a/src/App/Services/CipherService.cs +++ b/src/App/Services/CipherService.cs @@ -25,6 +25,7 @@ namespace Bit.App.Services private readonly ICipherApiRepository _cipherApiRepository; private readonly ISettingsService _settingsService; private readonly ICryptoService _cryptoService; + private readonly IAppSettingsService _appSettingsService; public CipherService( ICipherRepository cipherRepository, @@ -33,7 +34,8 @@ namespace Bit.App.Services IAuthService authService, ICipherApiRepository cipherApiRepository, ISettingsService settingsService, - ICryptoService cryptoService) + ICryptoService cryptoService, + IAppSettingsService appSettingsService) { _cipherRepository = cipherRepository; _cipherCollectionRepository = cipherCollectionRepository; @@ -42,6 +44,7 @@ namespace Bit.App.Services _cipherApiRepository = cipherApiRepository; _settingsService = settingsService; _cryptoService = cryptoService; + _appSettingsService = appSettingsService; } public async Task GetByIdAsync(string id) @@ -59,6 +62,12 @@ namespace Bit.App.Services public async Task> GetAllAsync() { + if(_appSettingsService.ClearCiphersCache) + { + CachedCiphers = null; + _appSettingsService.ClearCiphersCache = false; + } + if(CachedCiphers != null) { return CachedCiphers; @@ -261,6 +270,7 @@ namespace Bit.App.Services { await _cipherRepository.UpsertAsync(cipher); CachedCiphers = null; + _appSettingsService.ClearCiphersCache = true; } public async Task DeleteAsync(string id) @@ -283,6 +293,7 @@ namespace Bit.App.Services { await _cipherRepository.DeleteAsync(id); CachedCiphers = null; + _appSettingsService.ClearCiphersCache = true; } public async Task DownloadAndDecryptAttachmentAsync(string url, string orgId = null) @@ -348,6 +359,7 @@ namespace Bit.App.Services await _attachmentRepository.UpsertAsync(attachment); } CachedCiphers = null; + _appSettingsService.ClearCiphersCache = true; } public async Task DeleteAttachmentAsync(Cipher cipher, string attachmentId) @@ -370,6 +382,7 @@ namespace Bit.App.Services { await _attachmentRepository.DeleteAsync(attachmentId); CachedCiphers = null; + _appSettingsService.ClearCiphersCache = true; } private Tuple InfoFromMobileAppUri(string mobileAppUriString)