TF-1217 Register cache adapter
This commit is contained in:
@@ -13,7 +13,7 @@ class CachingManager {
|
|||||||
final EmailCacheClient _emailCacheClient;
|
final EmailCacheClient _emailCacheClient;
|
||||||
final RecentSearchCacheClient _recentSearchCacheClient;
|
final RecentSearchCacheClient _recentSearchCacheClient;
|
||||||
final AccountCacheClient _accountCacheClient;
|
final AccountCacheClient _accountCacheClient;
|
||||||
final FcmTokenCacheClient _firebaseCacheClient;
|
final FcmTokenCacheClient _fcmTokenCacheClient;
|
||||||
|
|
||||||
CachingManager(
|
CachingManager(
|
||||||
this._mailboxCacheClient,
|
this._mailboxCacheClient,
|
||||||
@@ -21,7 +21,7 @@ class CachingManager {
|
|||||||
this._emailCacheClient,
|
this._emailCacheClient,
|
||||||
this._recentSearchCacheClient,
|
this._recentSearchCacheClient,
|
||||||
this._accountCacheClient,
|
this._accountCacheClient,
|
||||||
this._firebaseCacheClient,
|
this._fcmTokenCacheClient,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> clearAll() async {
|
Future<void> clearAll() async {
|
||||||
@@ -32,6 +32,7 @@ class CachingManager {
|
|||||||
_emailCacheClient.clearAllData(),
|
_emailCacheClient.clearAllData(),
|
||||||
_recentSearchCacheClient.clearAllData(),
|
_recentSearchCacheClient.clearAllData(),
|
||||||
_accountCacheClient.clearAllData(),
|
_accountCacheClient.clearAllData(),
|
||||||
|
_fcmTokenCacheClient.clearAllData(),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
@@ -40,15 +41,22 @@ class CachingManager {
|
|||||||
_emailCacheClient.deleteBox(),
|
_emailCacheClient.deleteBox(),
|
||||||
_recentSearchCacheClient.deleteBox(),
|
_recentSearchCacheClient.deleteBox(),
|
||||||
_accountCacheClient.deleteBox(),
|
_accountCacheClient.deleteBox(),
|
||||||
_firebaseCacheClient.deleteBox(),
|
_fcmTokenCacheClient.deleteBox(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cleanEmailCache() async {
|
Future<void> cleanEmailCache() async {
|
||||||
await Future.wait([
|
if (kIsWeb) {
|
||||||
_stateCacheClient.deleteItem(StateType.email.value),
|
await Future.wait([
|
||||||
_emailCacheClient.clearAllData(),
|
_stateCacheClient.deleteItem(StateType.email.value),
|
||||||
]);
|
_emailCacheClient.clearAllData(),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
await Future.wait([
|
||||||
|
_stateCacheClient.deleteItem(StateType.email.value),
|
||||||
|
_emailCacheClient.deleteBox(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ abstract class HiveCacheClient<T> {
|
|||||||
Future<Box<T>> openBox() async {
|
Future<Box<T>> openBox() async {
|
||||||
if (Hive.isBoxOpen(tableName)) {
|
if (Hive.isBoxOpen(tableName)) {
|
||||||
return Hive.box<T>(tableName);
|
return Hive.box<T>(tableName);
|
||||||
|
} else {
|
||||||
|
return Hive.openBox<T>(tableName);
|
||||||
}
|
}
|
||||||
return Hive.openBox<T>(tableName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Box<T>> openBoxEncryption() async {
|
Future<Box<T>> openBoxEncryption() async {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:core/utils/app_logger.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||||
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/local/encryption_key_cache_manager.dart';
|
import 'package:tmail_ui_user/features/login/data/local/encryption_key_cache_manager.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
|
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
|
||||||
@@ -66,20 +67,68 @@ class HiveCacheConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void registerAdapter() {
|
void registerAdapter() {
|
||||||
Hive.registerAdapter(MailboxCacheAdapter());
|
registerCacheAdapter<MailboxCache>(
|
||||||
Hive.registerAdapter(MailboxRightsCacheAdapter());
|
MailboxCacheAdapter(),
|
||||||
Hive.registerAdapter(StateCacheAdapter());
|
CachingConstants.MAILBOX_CACHE_IDENTIFY
|
||||||
Hive.registerAdapter(StateTypeAdapter());
|
);
|
||||||
Hive.registerAdapter(EmailAddressHiveCacheAdapter());
|
registerCacheAdapter<MailboxRightsCache>(
|
||||||
Hive.registerAdapter(EmailCacheAdapter());
|
MailboxRightsCacheAdapter(),
|
||||||
Hive.registerAdapter(RecentSearchCacheAdapter());
|
CachingConstants.MAILBOX_RIGHTS_CACHE_IDENTIFY
|
||||||
Hive.registerAdapter(TokenOidcCacheAdapter());
|
);
|
||||||
Hive.registerAdapter(AccountCacheAdapter());
|
registerCacheAdapter<StateCache>(
|
||||||
Hive.registerAdapter(EncryptionKeyCacheAdapter());
|
StateCacheAdapter(),
|
||||||
Hive.registerAdapter(AuthenticationInfoCacheAdapter());
|
CachingConstants.STATE_CACHE_IDENTIFY
|
||||||
Hive.registerAdapter(RecentLoginUrlCacheAdapter());
|
);
|
||||||
Hive.registerAdapter(RecentLoginUsernameCacheAdapter());
|
registerCacheAdapter<StateType>(
|
||||||
Hive.registerAdapter(FCMTokenCacheAdapter());
|
StateTypeAdapter(),
|
||||||
|
CachingConstants.STATE_TYPE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<EmailAddressHiveCache>(
|
||||||
|
EmailAddressHiveCacheAdapter(),
|
||||||
|
CachingConstants.EMAIL_ADDRESS_HIVE_CACHE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<EmailCache>(
|
||||||
|
EmailCacheAdapter(),
|
||||||
|
CachingConstants.EMAIL_CACHE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<RecentSearchCache>(
|
||||||
|
RecentSearchCacheAdapter(),
|
||||||
|
CachingConstants.RECENT_SEARCH_HIVE_CACHE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<TokenOidcCache>(
|
||||||
|
TokenOidcCacheAdapter(),
|
||||||
|
CachingConstants.TOKEN_OIDC_HIVE_CACHE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<AccountCache>(
|
||||||
|
AccountCacheAdapter(),
|
||||||
|
CachingConstants.ACCOUNT_HIVE_CACHE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<EncryptionKeyCache>(
|
||||||
|
EncryptionKeyCacheAdapter(),
|
||||||
|
CachingConstants.ENCRYPTION_KEY_HIVE_CACHE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<AuthenticationInfoCache>(
|
||||||
|
AuthenticationInfoCacheAdapter(),
|
||||||
|
CachingConstants.AUTHENTICATION_INFO_HIVE_CACHE_IDENTIFY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<RecentLoginUrlCache>(
|
||||||
|
RecentLoginUrlCacheAdapter(),
|
||||||
|
CachingConstants.RECENT_LOGIN_URL_HIVE_CACHE_IDENTITY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<RecentLoginUsernameCache>(
|
||||||
|
RecentLoginUsernameCacheAdapter(),
|
||||||
|
CachingConstants.RECENT_LOGIN_USERNAME_HIVE_CACHE_IDENTITY
|
||||||
|
);
|
||||||
|
registerCacheAdapter<FCMTokenCache>(
|
||||||
|
FCMTokenCacheAdapter(),
|
||||||
|
CachingConstants.FCM_TOKEN_CACHE_IDENTITY
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void registerCacheAdapter<T>(TypeAdapter<T> typeAdapter, int typeId) {
|
||||||
|
if (!Hive.isAdapterRegistered(typeId)) {
|
||||||
|
Hive.registerAdapter<T>(typeAdapter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future closeHive() async {
|
Future closeHive() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user