diff --git a/lib/features/caching/config/hive_cache_client.dart b/lib/features/caching/config/hive_cache_client.dart index 3da0e9f3e..9eb485bce 100644 --- a/lib/features/caching/config/hive_cache_client.dart +++ b/lib/features/caching/config/hive_cache_client.dart @@ -52,12 +52,8 @@ abstract class HiveCacheClient { }); } - Future getItem(String key, {bool needToReopen = false}) { - log('$runtimeType::getItem() key: $encryption - needToReopen: $needToReopen'); + Future getItem(String key) { return Future.sync(() async { - if (needToReopen) { - await closeBox(); - } final boxItem = encryption ? await openBoxEncryption() : await openBox(); diff --git a/lib/features/login/data/local/account_cache_manager.dart b/lib/features/login/data/local/account_cache_manager.dart index 4b2403d3d..fb0e11298 100644 --- a/lib/features/login/data/local/account_cache_manager.dart +++ b/lib/features/login/data/local/account_cache_manager.dart @@ -47,6 +47,4 @@ class AccountCacheManager { log('AccountCacheManager::deleteCurrentAccount(): $hashId'); return _accountCacheClient.deleteItem(hashId); } - - Future closeAccountHiveCacheBox() => _accountCacheClient.closeBox(); } \ No newline at end of file diff --git a/lib/features/login/data/local/authentication_info_cache_manager.dart b/lib/features/login/data/local/authentication_info_cache_manager.dart index 6b11d8451..a9089267f 100644 --- a/lib/features/login/data/local/authentication_info_cache_manager.dart +++ b/lib/features/login/data/local/authentication_info_cache_manager.dart @@ -25,6 +25,4 @@ class AuthenticationInfoCacheManager { Future removeAuthenticationInfo() { return _authenticationInfoCacheClient.deleteItem(AuthenticationInfoCache.keyCacheValue); } - - Future closeAuthenticationInfoHiveCacheBox() => _authenticationInfoCacheClient.closeBox(); } \ No newline at end of file diff --git a/lib/features/login/data/local/token_oidc_cache_manager.dart b/lib/features/login/data/local/token_oidc_cache_manager.dart index 83e015428..c124a5b83 100644 --- a/lib/features/login/data/local/token_oidc_cache_manager.dart +++ b/lib/features/login/data/local/token_oidc_cache_manager.dart @@ -34,6 +34,4 @@ class TokenOidcCacheManager { Future deleteTokenOidc() async { await _tokenOidcCacheClient.clearAllData(); } - - Future closeTokenOIDCHiveCacheBox() => _tokenOidcCacheClient.closeBox(); } \ No newline at end of file diff --git a/lib/features/mailbox/data/local/state_cache_manager.dart b/lib/features/mailbox/data/local/state_cache_manager.dart index 8d9b3e7f3..30e3ffa92 100644 --- a/lib/features/mailbox/data/local/state_cache_manager.dart +++ b/lib/features/mailbox/data/local/state_cache_manager.dart @@ -29,6 +29,4 @@ class StateCacheManager { final stateKey = TupleKey(stateType.name, accountId.asString, userName.value).encodeKey; return await _stateCacheClient.deleteItem(stateKey); } - - Future closeStateHiveCacheBox() => _stateCacheClient.closeBox(); } \ No newline at end of file diff --git a/lib/features/offline_mode/manager/new_email_cache_manager.dart b/lib/features/offline_mode/manager/new_email_cache_manager.dart index 9040bbe90..5a143df0b 100644 --- a/lib/features/offline_mode/manager/new_email_cache_manager.dart +++ b/lib/features/offline_mode/manager/new_email_cache_manager.dart @@ -76,13 +76,11 @@ class NewEmailCacheManager { EmailId emailId ) async { final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey; - final detailedEmailCache = await _cacheClient.getItem(keyCache, needToReopen: true); + final detailedEmailCache = await _cacheClient.getItem(keyCache); if (detailedEmailCache != null) { return detailedEmailCache; } else { throw NotFoundStoredNewEmailException(); } } - - Future closeNewEmailHiveCacheBox() => _cacheClient.closeBox(); } \ No newline at end of file diff --git a/lib/features/offline_mode/manager/opened_email_cache_manager.dart b/lib/features/offline_mode/manager/opened_email_cache_manager.dart index a523ffe7a..6aee303a2 100644 --- a/lib/features/offline_mode/manager/opened_email_cache_manager.dart +++ b/lib/features/offline_mode/manager/opened_email_cache_manager.dart @@ -74,7 +74,7 @@ class OpenedEmailCacheManager { EmailId emailId ) async { final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey; - final detailedEmailCache = await _cacheClient.getItem(keyCache, needToReopen: true); + final detailedEmailCache = await _cacheClient.getItem(keyCache); if (detailedEmailCache != null) { return detailedEmailCache; } else { diff --git a/lib/features/push_notification/data/local/fcm_cache_manager.dart b/lib/features/push_notification/data/local/fcm_cache_manager.dart index 7a2848fd6..f841cb83e 100644 --- a/lib/features/push_notification/data/local/fcm_cache_manager.dart +++ b/lib/features/push_notification/data/local/fcm_cache_manager.dart @@ -23,7 +23,7 @@ class FCMCacheManager { Future getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) async { final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey; - final stateValue = await _fcmCacheClient.getItem(stateKeyCache, needToReopen: true); + final stateValue = await _fcmCacheClient.getItem(stateKeyCache); if (stateValue != null) { return jmap.State(stateValue); } else { @@ -52,7 +52,7 @@ class FCMCacheManager { } Future getStoredFirebaseRegistration() async { - final firebaseRegistration = await _firebaseRegistrationCacheClient.getItem(FirebaseRegistrationCache.keyCacheValue, needToReopen: true); + final firebaseRegistration = await _firebaseRegistrationCacheClient.getItem(FirebaseRegistrationCache.keyCacheValue); if (firebaseRegistration == null) { throw NotFoundFirebaseRegistrationCacheException(); } else { diff --git a/lib/features/push_notification/presentation/controller/fcm_message_controller.dart b/lib/features/push_notification/presentation/controller/fcm_message_controller.dart index 5782f3ed5..4ac6f86fb 100644 --- a/lib/features/push_notification/presentation/controller/fcm_message_controller.dart +++ b/lib/features/push_notification/presentation/controller/fcm_message_controller.dart @@ -17,14 +17,10 @@ import 'package:tmail_ui_user/features/home/domain/extensions/session_extensions import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart'; import 'package:tmail_ui_user/features/home/domain/usecases/get_session_interactor.dart'; import 'package:tmail_ui_user/features/home/presentation/home_bindings.dart'; -import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart'; -import 'package:tmail_ui_user/features/login/data/local/authentication_info_cache_manager.dart'; -import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart'; import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart'; import 'package:tmail_ui_user/features/login/domain/state/get_credential_state.dart'; import 'package:tmail_ui_user/features/login/domain/state/get_stored_token_oidc_state.dart'; import 'package:tmail_ui_user/features/login/domain/usecases/get_authenticated_account_interactor.dart'; -import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart'; import 'package:tmail_ui_user/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart'; import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_token_controller.dart'; @@ -43,11 +39,6 @@ class FcmMessageController extends PushBaseController { AuthorizationInterceptors? _authorizationInterceptors; GetSessionInteractor? _getSessionInteractor; - AccountCacheManager? _accountCacheManager; - TokenOidcCacheManager? _tokenOidcCacheManager; - StateCacheManager? _stateCacheManager; - AuthenticationInfoCacheManager? _authenticationInfoCacheManager; - FcmMessageController._internal(); static final FcmMessageController _instance = FcmMessageController._internal(); @@ -96,17 +87,6 @@ class FcmMessageController extends PushBaseController { }); _getInteractorBindings(); - - await Future.wait([ - if (_accountCacheManager != null) - _accountCacheManager!.closeAccountHiveCacheBox(), - if (_tokenOidcCacheManager != null) - _tokenOidcCacheManager!.closeTokenOIDCHiveCacheBox(), - if (_stateCacheManager != null) - _stateCacheManager!.closeStateHiveCacheBox(), - if (_authenticationInfoCacheManager != null) - _authenticationInfoCacheManager!.closeAuthenticationInfoHiveCacheBox(), - ]); } void _getInteractorBindings() { @@ -114,10 +94,6 @@ class FcmMessageController extends PushBaseController { _dynamicUrlInterceptors = getBinding(); _authorizationInterceptors = getBinding(); _getSessionInteractor = getBinding(); - _accountCacheManager = getBinding(); - _tokenOidcCacheManager = getBinding(); - _stateCacheManager = getBinding(); - _authenticationInfoCacheManager = getBinding(); FcmTokenController.instance.initialBindingInteractor(); } diff --git a/lib/features/thread/data/extensions/email_cache_extension.dart b/lib/features/thread/data/extensions/email_cache_extension.dart index 31d6f9fe7..9c8ab6de7 100644 --- a/lib/features/thread/data/extensions/email_cache_extension.dart +++ b/lib/features/thread/data/extensions/email_cache_extension.dart @@ -56,12 +56,16 @@ extension EmailCacheExtension on EmailCache { bool expireTimeCaching(EmailCleanupRule cleanupRule) { final currentTime = DateTime.now(); + log('EmailCacheExtension::expireTimeCaching():currentTime: $currentTime | receivedAt: $receivedAt'); if (receivedAt != null) { final countDay = currentTime.daysBetween(receivedAt!.toLocal()); + log('EmailCacheExtension::expireTimeCaching():countDay: $countDay | cleanupRule.cachingEmailPeriod.countDay: ${cleanupRule.cachingEmailPeriod.countDay}'); if (countDay >= cleanupRule.cachingEmailPeriod.countDay) { + log('EmailCacheExtension::expireTimeCaching():true'); return true; } } + log('EmailCacheExtension::expireTimeCaching():false'); return false; } } \ No newline at end of file diff --git a/lib/features/thread/data/local/email_cache_manager.dart b/lib/features/thread/data/local/email_cache_manager.dart index fe5b17683..dfc352b12 100644 --- a/lib/features/thread/data/local/email_cache_manager.dart +++ b/lib/features/thread/data/local/email_cache_manager.dart @@ -111,7 +111,7 @@ class EmailCacheManager { Future getStoredEmail(AccountId accountId, UserName userName, EmailId emailId) async { final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey; - final emailCache = await _emailCacheClient.getItem(keyCache, needToReopen: true); + final emailCache = await _emailCacheClient.getItem(keyCache); if (emailCache != null) { return emailCache; } else { diff --git a/test/features/login/data/local/memory_account_cache_client.dart b/test/features/login/data/local/memory_account_cache_client.dart index e4349a76e..1005ba1d2 100644 --- a/test/features/login/data/local/memory_account_cache_client.dart +++ b/test/features/login/data/local/memory_account_cache_client.dart @@ -48,7 +48,7 @@ class MemoryAccountCacheClient implements AccountCacheClient { } @override - Future getItem(String key, {bool needToReopen = false}) { + Future getItem(String key) { return Future.value(_cache[key]); }