TF-624 Handling asynchronous when clearing cache

This commit is contained in:
dab246
2022-06-09 15:41:47 +07:00
committed by Dat H. Pham
parent d463dbed47
commit 34f3cfd6b1
6 changed files with 78 additions and 64 deletions
+21 -22
View File
@@ -11,8 +11,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<void> clearAllData() {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.clear();
final boxAccount = await openBox();
return boxAccount.clear();
}).catchError((error) {
throw error;
});
@@ -21,8 +21,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<void> deleteItem(String key) {
return Future.sync(() async {
final boxToken = await openBox();
return boxToken.delete(key);
final boxAccount = await openBox();
return boxAccount.delete(key);
}).catchError((error) {
throw error;
});
@@ -31,8 +31,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<void> deleteMultipleItem(List<String> listKey) {
return Future.sync(() async {
final boxToken = await openBox();
return boxToken.deleteAll(listKey);
final boxAccount = await openBox();
return boxAccount.deleteAll(listKey);
}).catchError((error) {
throw error;
});
@@ -41,8 +41,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<List<AccountCache>> getAll() {
return Future.sync(() async {
final boxToken = await openBox();
return boxToken.values.toList();
final boxAccount = await openBox();
return boxAccount.values.toList();
}).catchError((error) {
throw error;
});
@@ -51,8 +51,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<AccountCache?> getItem(String key) {
return Future.sync(() async {
final boxToken = await openBox();
return boxToken.get(key);
final boxAccount = await openBox();
return boxAccount.get(key);
}).catchError((error) {
throw error;
});
@@ -62,8 +62,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
Future<void> insertItem(String key, AccountCache newObject) {
log('AccountCacheClient::insertItem(): $key: $newObject');
return Future.sync(() async {
final boxToken = await openBox();
boxToken.put(key, newObject);
final boxAccount = await openBox();
return boxAccount.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -72,8 +72,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<void> insertMultipleItem(Map<String, AccountCache> mapObject) {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.putAll(mapObject);
final boxAccount = await openBox();
return boxAccount.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -82,8 +82,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<bool> isExistItem(String key) {
return Future.sync(() async {
final boxToken = await openBox();
return boxToken.containsKey(key);
final boxAccount = await openBox();
return boxAccount.containsKey(key);
}).catchError((error) {
throw error;
});
@@ -92,7 +92,7 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<bool> isExistTable() {
return Future.sync(() async {
return await Hive.boxExists(tableName);
return Hive.boxExists(tableName);
}).catchError((error) {
throw error;
});
@@ -109,8 +109,8 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<void> updateItem(String key, AccountCache newObject) {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.put(key, newObject);
final boxAccount = await openBox();
return boxAccount.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -119,11 +119,10 @@ class AccountCacheClient extends HiveCacheClient<AccountCache> {
@override
Future<void> updateMultipleItem(Map<String, AccountCache> mapObject) {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.putAll(mapObject);
final boxAccount = await openBox();
return boxAccount.putAll(mapObject);
}).catchError((error) {
throw error;
});
}
}
+6 -6
View File
@@ -62,7 +62,7 @@ class EmailCacheClient extends HiveCacheClient<EmailCache> {
Future<void> insertItem(String key, EmailCache newObject) {
return Future.sync(() async {
final boxEmail = await openBox();
boxEmail.put(key, newObject);
return boxEmail.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -72,7 +72,7 @@ class EmailCacheClient extends HiveCacheClient<EmailCache> {
Future<void> insertMultipleItem(Map<String, EmailCache> mapObject) {
return Future.sync(() async {
final boxEmail = await openBox();
boxEmail.putAll(mapObject);
return boxEmail.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -82,7 +82,7 @@ class EmailCacheClient extends HiveCacheClient<EmailCache> {
Future<void> updateItem(String key, EmailCache newObject) {
return Future.sync(() async {
final boxEmail = await openBox();
boxEmail.put(key, newObject);
return boxEmail.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -91,7 +91,7 @@ class EmailCacheClient extends HiveCacheClient<EmailCache> {
@override
Future<bool> isExistTable() {
return Future.sync(() async {
return await Hive.boxExists(tableName);
return Hive.boxExists(tableName);
}).catchError((error) {
throw error;
});
@@ -113,7 +113,7 @@ class EmailCacheClient extends HiveCacheClient<EmailCache> {
Future<void> updateMultipleItem(Map<String, EmailCache> mapObject) {
return Future.sync(() async {
final boxEmail = await openBox();
boxEmail.putAll(mapObject);
return boxEmail.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -136,7 +136,7 @@ class EmailCacheClient extends HiveCacheClient<EmailCache> {
Future<void> clearAllData() {
return Future.sync(() async {
final boxEmail = await openBox();
boxEmail.clear();
return boxEmail.clear();
}).catchError((error) {
throw error;
});
@@ -60,7 +60,7 @@ class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
Future<void> insertItem(String key, MailboxCache newObject) {
return Future.sync(() async {
final boxMailbox = await openBox();
boxMailbox.put(key, newObject);
return boxMailbox.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -70,7 +70,7 @@ class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
Future<void> insertMultipleItem(Map<String, MailboxCache> mapObject) {
return Future.sync(() async {
final boxMailbox = await openBox();
boxMailbox.putAll(mapObject);
return boxMailbox.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -80,7 +80,7 @@ class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
Future<void> updateItem(String key, MailboxCache newObject) {
return Future.sync(() async {
final boxMailbox = await openBox();
boxMailbox.put(key, newObject);
return boxMailbox.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -89,7 +89,7 @@ class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
@override
Future<bool> isExistTable() {
return Future.sync(() async {
return await Hive.boxExists(tableName);
return Hive.boxExists(tableName);
}).catchError((error) {
throw error;
});
@@ -109,7 +109,7 @@ class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
Future<void> updateMultipleItem(Map<String, MailboxCache> mapObject) {
return Future.sync(() async {
final boxMailbox = await openBox();
boxMailbox.putAll(mapObject);
return boxMailbox.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -119,7 +119,7 @@ class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
Future<void> clearAllData() {
return Future.sync(() async {
final boxMailbox = await openBox();
boxMailbox.clear();
return boxMailbox.clear();
}).catchError((error) {
throw error;
});
@@ -11,8 +11,8 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<void> clearAllData() {
return Future.sync(() async {
final boxState = await openBox();
boxState.clear();
final boxRecent = await openBox();
return boxRecent.clear();
}).catchError((error) {
throw error;
});
@@ -21,8 +21,8 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<void> deleteItem(String key) {
return Future.sync(() async {
final boxState = await openBox();
return boxState.delete(key);
final boxRecent = await openBox();
return boxRecent.delete(key);
}).catchError((error) {
throw error;
});
@@ -31,8 +31,8 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<void> deleteMultipleItem(List<String> listKey) {
return Future.sync(() async {
final boxEmail = await openBox();
return boxEmail.deleteAll(listKey);
final boxRecent = await openBox();
return boxRecent.deleteAll(listKey);
}).catchError((error) {
throw error;
});
@@ -41,8 +41,8 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<List<RecentSearchCache>> getAll() {
return Future.sync(() async {
final boxState = await openBox();
return boxState.values.toList();
final boxRecent = await openBox();
return boxRecent.values.toList();
}).catchError((error) {
throw error;
});
@@ -50,14 +50,19 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<RecentSearchCache?> getItem(String key) {
throw UnimplementedError();
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.get(key);
}).catchError((error) {
throw error;
});
}
@override
Future<void> insertItem(String key, RecentSearchCache newObject) {
return Future.sync(() async {
final boxState = await openBox();
boxState.put(key, newObject);
final boxRecent = await openBox();
return boxRecent.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -65,14 +70,19 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<void> insertMultipleItem(Map<String, RecentSearchCache> mapObject) {
throw UnimplementedError();
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.putAll(mapObject);
}).catchError((error) {
throw error;
});
}
@override
Future<bool> isExistItem(String key) {
return Future.sync(() async {
final boxState = await openBox();
return boxState.containsKey(key);
final boxRecent = await openBox();
return boxRecent.containsKey(key);
}).catchError((error) {
throw error;
});
@@ -81,7 +91,7 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<bool> isExistTable() {
return Future.sync(() async {
return await Hive.boxExists(tableName);
return Hive.boxExists(tableName);
}).catchError((error) {
throw error;
});
@@ -98,8 +108,8 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<void> updateItem(String key, RecentSearchCache newObject) {
return Future.sync(() async {
final boxState = await openBox();
boxState.put(key, newObject);
final boxRecent = await openBox();
return boxRecent.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -107,6 +117,11 @@ class RecentSearchCacheClient extends HiveCacheClient<RecentSearchCache> {
@override
Future<void> updateMultipleItem(Map<String, RecentSearchCache> mapObject) {
throw UnimplementedError();
return Future.sync(() async {
final boxRecent = await openBox();
return boxRecent.putAll(mapObject);
}).catchError((error) {
throw error;
});
}
}
+6 -6
View File
@@ -60,7 +60,7 @@ class StateCacheClient extends HiveCacheClient<StateCache> {
Future<void> insertItem(String key, StateCache newObject) {
return Future.sync(() async {
final boxState = await openBox();
boxState.put(key, newObject);
return boxState.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -70,7 +70,7 @@ class StateCacheClient extends HiveCacheClient<StateCache> {
Future<void> insertMultipleItem(Map<String, StateCache> mapObject) {
return Future.sync(() async {
final boxState = await openBox();
boxState.putAll(mapObject);
return boxState.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -80,7 +80,7 @@ class StateCacheClient extends HiveCacheClient<StateCache> {
Future<void> updateItem(String key, StateCache newObject) {
return Future.sync(() async {
final boxState = await openBox();
boxState.put(key, newObject);
return boxState.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -99,7 +99,7 @@ class StateCacheClient extends HiveCacheClient<StateCache> {
Future<void> deleteMultipleItem(List<String> listKey) {
return Future.sync(() async {
final boxState = await openBox();
boxState.deleteAll(listKey);
return boxState.deleteAll(listKey);
}).catchError((error) {
throw error;
});
@@ -109,7 +109,7 @@ class StateCacheClient extends HiveCacheClient<StateCache> {
Future<void> updateMultipleItem(Map<String, StateCache> mapObject) {
return Future.sync(() async {
final boxState = await openBox();
boxState.putAll(mapObject);
return boxState.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -119,7 +119,7 @@ class StateCacheClient extends HiveCacheClient<StateCache> {
Future<void> clearAllData() {
return Future.sync(() async {
final boxState = await openBox();
boxState.clear();
return boxState.clear();
}).catchError((error) {
throw error;
});
@@ -11,7 +11,7 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
Future<void> clearAllData() {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.clear();
return boxToken.clear();
}).catchError((error) {
throw error;
});
@@ -61,7 +61,7 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
Future<void> insertItem(String key, TokenOidcCache newObject) {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.put(key, newObject);
return boxToken.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -71,7 +71,7 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
Future<void> insertMultipleItem(Map<String, TokenOidcCache> mapObject) {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.putAll(mapObject);
return boxToken.putAll(mapObject);
}).catchError((error) {
throw error;
});
@@ -90,7 +90,7 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
@override
Future<bool> isExistTable() {
return Future.sync(() async {
return await Hive.boxExists(tableName);
return Hive.boxExists(tableName);
}).catchError((error) {
throw error;
});
@@ -108,7 +108,7 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
Future<void> updateItem(String key, TokenOidcCache newObject) {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.put(key, newObject);
return boxToken.put(key, newObject);
}).catchError((error) {
throw error;
});
@@ -118,7 +118,7 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
Future<void> updateMultipleItem(Map<String, TokenOidcCache> mapObject) {
return Future.sync(() async {
final boxToken = await openBox();
boxToken.putAll(mapObject);
return boxToken.putAll(mapObject);
}).catchError((error) {
throw error;
});