From e753acbc3f1ef1064ac5fad2c14749b7b31e8ec6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 27 Nov 2017 15:11:06 -0500 Subject: [PATCH] clear cache on logout --- src/App/Services/AuthService.cs | 1 + src/App/Services/CipherService.cs | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/App/Services/AuthService.cs b/src/App/Services/AuthService.cs index e73082537..ab271946f 100644 --- a/src/App/Services/AuthService.cs +++ b/src/App/Services/AuthService.cs @@ -209,6 +209,7 @@ namespace Bit.App.Services public void LogOut(string logoutMessage = null) { + CipherService.CachedCiphers = null; _tokenService.Token = null; _tokenService.RefreshToken = null; UserId = null; diff --git a/src/App/Services/CipherService.cs b/src/App/Services/CipherService.cs index ad6a6fa8e..c71fd9da2 100644 --- a/src/App/Services/CipherService.cs +++ b/src/App/Services/CipherService.cs @@ -6,13 +6,14 @@ using Bit.App.Abstractions; using Bit.App.Models; using Bit.App.Models.Api; using Bit.App.Models.Data; -using Xamarin.Forms; using System.Net.Http; namespace Bit.App.Services { public class CipherService : ICipherService { + public static List CachedCiphers = null; + private readonly string[] _ignoredSearchTerms = new string[] { "com", "net", "org", "android", "io", "co", "uk", "au", "nz", "fr", "de", "tv", "info", "app", "apps", "eu", "me", "dev", "jp", "mobile" }; private readonly ICipherRepository _cipherRepository; @@ -23,8 +24,6 @@ namespace Bit.App.Services private readonly ISettingsService _settingsService; private readonly ICryptoService _cryptoService; - private List _cachedCiphers = null; - public CipherService( ICipherRepository cipherRepository, ICipherCollectionRepository cipherCollectionRepository, @@ -58,18 +57,18 @@ namespace Bit.App.Services public async Task> GetAllAsync() { - if(_cachedCiphers != null) + if(CachedCiphers != null) { - return _cachedCiphers; + return CachedCiphers; } var attachmentData = await _attachmentRepository.GetAllByUserIdAsync(_authService.UserId); var attachmentDict = attachmentData.GroupBy(a => a.LoginId).ToDictionary(g => g.Key, g => g.ToList()); var data = await _cipherRepository.GetAllByUserIdAsync(_authService.UserId); - _cachedCiphers = data + CachedCiphers = data .Select(f => new Cipher(f, attachmentDict.ContainsKey(f.Id) ? attachmentDict[f.Id] : null)) .ToList(); - return _cachedCiphers; + return CachedCiphers; } public async Task> GetAllAsync(bool favorites) @@ -273,7 +272,7 @@ namespace Bit.App.Services public async Task UpsertDataAsync(CipherData cipher) { await _cipherRepository.UpsertAsync(cipher); - _cachedCiphers = null; + CachedCiphers = null; } public async Task DeleteAsync(string id) @@ -295,7 +294,7 @@ namespace Bit.App.Services public async Task DeleteDataAsync(string id) { await _cipherRepository.DeleteAsync(id); - _cachedCiphers = null; + CachedCiphers = null; } public async Task DownloadAndDecryptAttachmentAsync(string url, string orgId = null) @@ -360,7 +359,7 @@ namespace Bit.App.Services { await _attachmentRepository.UpsertAsync(attachment); } - _cachedCiphers = null; + CachedCiphers = null; } public async Task DeleteAttachmentAsync(Cipher cipher, string attachmentId) @@ -382,7 +381,7 @@ namespace Bit.App.Services public async Task DeleteAttachmentDataAsync(string attachmentId) { await _attachmentRepository.DeleteAsync(attachmentId); - _cachedCiphers = null; + CachedCiphers = null; } private Tuple InfoFromMobileAppUri(string mobileAppUriString)