Mark cache version to clear cache data
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
abstract class CacheVersionClient {
|
||||||
|
|
||||||
|
String get versionKey;
|
||||||
|
|
||||||
|
Future<bool> storeVersion(int newVersion);
|
||||||
|
|
||||||
|
Future<int?> getLatestVersion();
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:tmail_ui_user/features/caching/account_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/account_cache_client.dart';
|
||||||
|
import 'package:tmail_ui_user/features/caching/config/cache_version.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/email_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/email_cache_client.dart';
|
||||||
|
import 'package:tmail_ui_user/features/caching/hive_cache_version_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/recent_search_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/recent_search_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
|
||||||
@@ -18,6 +19,7 @@ class CachingManager {
|
|||||||
final AccountCacheClient _accountCacheClient;
|
final AccountCacheClient _accountCacheClient;
|
||||||
final FCMCacheManager _fcmCacheManager;
|
final FCMCacheManager _fcmCacheManager;
|
||||||
final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient;
|
final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient;
|
||||||
|
final HiveCacheVersionClient _hiveCacheVersionClient;
|
||||||
|
|
||||||
CachingManager(
|
CachingManager(
|
||||||
this._mailboxCacheClient,
|
this._mailboxCacheClient,
|
||||||
@@ -27,6 +29,7 @@ class CachingManager {
|
|||||||
this._accountCacheClient,
|
this._accountCacheClient,
|
||||||
this._fcmCacheManager,
|
this._fcmCacheManager,
|
||||||
this._fcmSubscriptionCacheClient,
|
this._fcmSubscriptionCacheClient,
|
||||||
|
this._hiveCacheVersionClient,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> clearAll() async {
|
Future<void> clearAll() async {
|
||||||
@@ -41,18 +44,26 @@ class CachingManager {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cleanEmailCache() async {
|
Future<void> clearEmailCache() async {
|
||||||
if (kIsWeb) {
|
await Future.wait([
|
||||||
await Future.wait([
|
_stateCacheClient.deleteItem(StateType.email.value),
|
||||||
_stateCacheClient.deleteItem(StateType.email.value),
|
_emailCacheClient.clearAllData(),
|
||||||
_emailCacheClient.clearAllData(),
|
]);
|
||||||
]);
|
}
|
||||||
} else {
|
|
||||||
await Future.wait([
|
Future<void> clearMailboxCache() async {
|
||||||
_stateCacheClient.deleteItem(StateType.email.value),
|
await Future.wait([
|
||||||
_emailCacheClient.deleteBox(),
|
_stateCacheClient.deleteItem(StateType.mailbox.value),
|
||||||
]);
|
_mailboxCacheClient.clearAllData(),
|
||||||
}
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> storeCacheVersion() async {
|
||||||
|
return _hiveCacheVersionClient.storeVersion(CacheVersion.hiveDBVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int?> getLatestHiveCacheVersion() {
|
||||||
|
return _hiveCacheVersionClient.getLatestVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeHive() async {
|
Future<void> closeHive() async {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
class CacheVersion {
|
||||||
|
static const int hiveDBVersion = 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:tmail_ui_user/features/caching/cache_version_client.dart';
|
||||||
|
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||||
|
|
||||||
|
class HiveCacheVersionClient extends CacheVersionClient {
|
||||||
|
|
||||||
|
final SharedPreferences _sharedPreferences;
|
||||||
|
final ExceptionThrower _exceptionThrower;
|
||||||
|
|
||||||
|
HiveCacheVersionClient(this._sharedPreferences, this._exceptionThrower);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get versionKey => 'HiveCacheVersion';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<int?> getLatestVersion() {
|
||||||
|
return Future.sync(() {
|
||||||
|
final latestVersion = _sharedPreferences.getInt(versionKey);
|
||||||
|
return latestVersion;
|
||||||
|
}).catchError((error) {
|
||||||
|
_exceptionThrower.throwException(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> storeVersion(int newVersion) {
|
||||||
|
return Future.sync(() async {
|
||||||
|
return await _sharedPreferences.setInt(versionKey, newVersion);
|
||||||
|
}).catchError((error) {
|
||||||
|
_exceptionThrower.throwException(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import 'package:model/model.dart';
|
|||||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
||||||
|
import 'package:tmail_ui_user/features/caching/config/cache_version.dart';
|
||||||
import 'package:tmail_ui_user/features/cleanup/domain/model/cleanup_rule.dart';
|
import 'package:tmail_ui_user/features/cleanup/domain/model/cleanup_rule.dart';
|
||||||
import 'package:tmail_ui_user/features/cleanup/domain/model/email_cleanup_rule.dart';
|
import 'package:tmail_ui_user/features/cleanup/domain/model/email_cleanup_rule.dart';
|
||||||
import 'package:tmail_ui_user/features/cleanup/domain/model/recent_login_url_cleanup_rule.dart';
|
import 'package:tmail_ui_user/features/cleanup/domain/model/recent_login_url_cleanup_rule.dart';
|
||||||
@@ -91,6 +92,8 @@ class HomeController extends BaseController {
|
|||||||
static void downloadCallback(String id, DownloadTaskStatus status, int progress) {}
|
static void downloadCallback(String id, DownloadTaskStatus status, int progress) {}
|
||||||
|
|
||||||
void _cleanupCache() async {
|
void _cleanupCache() async {
|
||||||
|
await _checkCacheVersion();
|
||||||
|
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
_cleanupEmailCacheInteractor.execute(EmailCleanupRule(Duration.defaultCacheInternal)),
|
_cleanupEmailCacheInteractor.execute(EmailCleanupRule(Duration.defaultCacheInternal)),
|
||||||
_cleanupRecentSearchCacheInteractor.execute(RecentSearchCleanupRule()),
|
_cleanupRecentSearchCacheInteractor.execute(RecentSearchCleanupRule()),
|
||||||
@@ -99,6 +102,19 @@ class HomeController extends BaseController {
|
|||||||
]).then((value) => _getAuthenticatedAccount());
|
]).then((value) => _getAuthenticatedAccount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _checkCacheVersion() async {
|
||||||
|
final latestHiveCacheVersion = await _cachingManager.getLatestHiveCacheVersion();
|
||||||
|
log('HomeController::_checkCacheVersion():latestHiveCacheVersion: $latestHiveCacheVersion');
|
||||||
|
if (latestHiveCacheVersion == null || latestHiveCacheVersion < CacheVersion.hiveDBVersion) {
|
||||||
|
await Future.wait([
|
||||||
|
_cachingManager.clearMailboxCache(),
|
||||||
|
_cachingManager.clearEmailCache()
|
||||||
|
]);
|
||||||
|
await _cachingManager.storeCacheVersion();
|
||||||
|
}
|
||||||
|
return Future.value(null);
|
||||||
|
}
|
||||||
|
|
||||||
void _getAuthenticatedAccount() async {
|
void _getAuthenticatedAccount() async {
|
||||||
log('HomeController::_getAuthenticatedAccount()');
|
log('HomeController::_getAuthenticatedAccount()');
|
||||||
consumeState(_getAuthenticatedAccountInteractor.execute());
|
consumeState(_getAuthenticatedAccountInteractor.execute());
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
void _handleErrorGetAllOrRefreshChangesEmail(dynamic error) async {
|
void _handleErrorGetAllOrRefreshChangesEmail(dynamic error) async {
|
||||||
logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error');
|
logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error');
|
||||||
if (error is CannotCalculateChangesMethodResponseException) {
|
if (error is CannotCalculateChangesMethodResponseException) {
|
||||||
await _cachingManager.cleanEmailCache();
|
await _cachingManager.clearEmailCache();
|
||||||
_getAllEmail();
|
_getAllEmail();
|
||||||
} else {
|
} else {
|
||||||
super.onError(error);
|
super.onError(error);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:tmail_ui_user/features/caching/authentication_info_cache_client.
|
|||||||
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/email_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/email_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/encryption_key_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/encryption_key_cache_client.dart';
|
||||||
|
import 'package:tmail_ui_user/features/caching/hive_cache_version_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/recent_login_url_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/recent_login_url_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/recent_login_username_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/recent_login_username_cache_client.dart';
|
||||||
@@ -32,8 +33,8 @@ class LocalBindings extends Bindings {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dependencies() {
|
void dependencies() {
|
||||||
_bindingCaching();
|
|
||||||
_bindingException();
|
_bindingException();
|
||||||
|
_bindingCaching();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bindingCaching() {
|
void _bindingCaching() {
|
||||||
@@ -60,6 +61,7 @@ class LocalBindings extends Bindings {
|
|||||||
Get.put(RecentLoginUsernameCacheManager(Get.find<RecentLoginUsernameCacheClient>()));
|
Get.put(RecentLoginUsernameCacheManager(Get.find<RecentLoginUsernameCacheClient>()));
|
||||||
Get.put(FCMSubscriptionCacheClient());
|
Get.put(FCMSubscriptionCacheClient());
|
||||||
Get.put(FCMCacheManager(Get.find<SharedPreferences>(),Get.find<FCMSubscriptionCacheClient>()));
|
Get.put(FCMCacheManager(Get.find<SharedPreferences>(),Get.find<FCMSubscriptionCacheClient>()));
|
||||||
|
Get.put(HiveCacheVersionClient(Get.find<SharedPreferences>(), Get.find<CacheExceptionThrower>()));
|
||||||
Get.put(CachingManager(
|
Get.put(CachingManager(
|
||||||
Get.find<MailboxCacheClient>(),
|
Get.find<MailboxCacheClient>(),
|
||||||
Get.find<StateCacheClient>(),
|
Get.find<StateCacheClient>(),
|
||||||
@@ -68,6 +70,7 @@ class LocalBindings extends Bindings {
|
|||||||
Get.find<AccountCacheClient>(),
|
Get.find<AccountCacheClient>(),
|
||||||
Get.find<FCMCacheManager>(),
|
Get.find<FCMCacheManager>(),
|
||||||
Get.find<FCMSubscriptionCacheClient>(),
|
Get.find<FCMSubscriptionCacheClient>(),
|
||||||
|
Get.find<HiveCacheVersionClient>()
|
||||||
));
|
));
|
||||||
Get.put(SharePreferenceSpamReportDataSource(Get.find<SharedPreferences>()));
|
Get.put(SharePreferenceSpamReportDataSource(Get.find<SharedPreferences>()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user