only clear cache if it hasnt been done in a while

This commit is contained in:
Kyle Spearrin 2017-07-13 11:11:04 -04:00
parent 352c8ee867
commit e0c67f87b0
6 changed files with 43 additions and 1 deletions

View file

@ -11,6 +11,13 @@ namespace Bit.Android.Services
{
public class DeviceActionService : IDeviceActionService
{
private readonly IAppSettingsService _appSettingsService;
public DeviceActionService(IAppSettingsService appSettingsService)
{
_appSettingsService = appSettingsService;
}
public void CopyToClipboard(string text)
{
var clipboardManager = (ClipboardManager)Forms.Context.GetSystemService(Context.ClipboardService);
@ -86,6 +93,7 @@ namespace Bit.Android.Services
try
{
DeleteDir(CrossCurrentActivity.Current.Activity.CacheDir);
_appSettingsService.LastCacheClear = DateTime.UtcNow;
}
catch(Exception) { }
}

View file

@ -6,6 +6,7 @@ namespace Bit.App.Abstractions
{
bool Locked { get; set; }
DateTime LastActivity { get; set; }
DateTime LastCacheClear { get; set; }
bool AutofillPersistNotification { get; set; }
bool AutofillPasswordField { get; set; }
string SecurityStamp { get; set; }

View file

@ -113,7 +113,11 @@ namespace Bit.App
await Task.Run(() => FullSyncAsync()).ConfigureAwait(false);
}
await Task.Run(() => _deviceActionService.ClearCache()).ConfigureAwait(false);
if((DateTime.UtcNow - _appSettingsService.LastCacheClear).TotalDays >= 1)
{
await Task.Run(() => _deviceActionService.ClearCache()).ConfigureAwait(false);
}
Debug.WriteLine("OnStart");
}
@ -156,6 +160,13 @@ namespace Bit.App
{
await Task.Run(() => FullSyncAsync()).ConfigureAwait(false);
}
var now = DateTime.UtcNow;
if((now - _appSettingsService.LastCacheClear).TotalDays >= 1
&& (now - _appSettingsService.LastActivity).TotalHours >= 1)
{
await Task.Run(() => _deviceActionService.ClearCache()).ConfigureAwait(false);
}
}
private void SetMainPageFromAutofill()

View file

@ -28,6 +28,7 @@
public const string SecurityStamp = "other:securityStamp";
public const string LastActivityDate = "other:lastActivityDate";
public const string LastCacheClearDate = "other:cacheClearDate";
public const string Locked = "other:locked";
public const string LastLoginEmail = "other:lastLoginEmail";
public const string LastSync = "other:lastSync";

View file

@ -38,6 +38,18 @@ namespace Bit.App.Services
}
}
public DateTime LastCacheClear
{
get
{
return _settings.GetValueOrDefault(Constants.LastCacheClearDate, DateTime.MinValue);
}
set
{
_settings.AddOrUpdateValue(Constants.LastCacheClearDate, value);
}
}
public bool AutofillPersistNotification
{
get

View file

@ -8,6 +8,13 @@ namespace Bit.iOS.Services
{
public class DeviceActionService : IDeviceActionService
{
private readonly IAppSettingsService _appSettingsService;
public DeviceActionService(IAppSettingsService appSettingsService)
{
_appSettingsService = appSettingsService;
}
public void CopyToClipboard(string text)
{
UIPasteboard clipboard = UIPasteboard.General;
@ -44,6 +51,8 @@ namespace Bit.iOS.Services
NSFileManager.DefaultManager.Remove(item, out itemError);
}
}
_appSettingsService.LastCacheClear = DateTime.UtcNow;
}
private UIViewController GetVisibleViewController(UIViewController controller = null)