From 34f3cfd6b1e25df2ef934cf9ee646cbbaaf3dbd1 Mon Sep 17 00:00:00 2001 From: dab246 Date: Thu, 9 Jun 2022 15:41:47 +0700 Subject: [PATCH] TF-624 Handling asynchronous when clearing cache --- .../caching/account_cache_client.dart | 43 ++++++++-------- lib/features/caching/email_cache_client.dart | 12 ++--- .../caching/mailbox_cache_client.dart | 12 ++--- .../caching/recent_search_cache_client.dart | 51 ++++++++++++------- lib/features/caching/state_cache_client.dart | 12 ++--- .../caching/token_oidc_cache_client.dart | 12 ++--- 6 files changed, 78 insertions(+), 64 deletions(-) diff --git a/lib/features/caching/account_cache_client.dart b/lib/features/caching/account_cache_client.dart index 4f3130eb1..ee00149fd 100644 --- a/lib/features/caching/account_cache_client.dart +++ b/lib/features/caching/account_cache_client.dart @@ -11,8 +11,8 @@ class AccountCacheClient extends HiveCacheClient { @override Future 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 { @override Future 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 { @override Future deleteMultipleItem(List 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 { @override Future> 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 { @override Future 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 { Future 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 { @override Future insertMultipleItem(Map 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 { @override Future 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 { @override Future 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 { @override Future 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 { @override Future updateMultipleItem(Map mapObject) { return Future.sync(() async { - final boxToken = await openBox(); - boxToken.putAll(mapObject); + final boxAccount = await openBox(); + return boxAccount.putAll(mapObject); }).catchError((error) { throw error; }); } - } \ No newline at end of file diff --git a/lib/features/caching/email_cache_client.dart b/lib/features/caching/email_cache_client.dart index c55ba18e4..70acc70be 100644 --- a/lib/features/caching/email_cache_client.dart +++ b/lib/features/caching/email_cache_client.dart @@ -62,7 +62,7 @@ class EmailCacheClient extends HiveCacheClient { Future 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 { Future insertMultipleItem(Map 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 { Future 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 { @override Future 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 { Future updateMultipleItem(Map 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 { Future clearAllData() { return Future.sync(() async { final boxEmail = await openBox(); - boxEmail.clear(); + return boxEmail.clear(); }).catchError((error) { throw error; }); diff --git a/lib/features/caching/mailbox_cache_client.dart b/lib/features/caching/mailbox_cache_client.dart index 92ee19a74..d6f1ad024 100644 --- a/lib/features/caching/mailbox_cache_client.dart +++ b/lib/features/caching/mailbox_cache_client.dart @@ -60,7 +60,7 @@ class MailboxCacheClient extends HiveCacheClient { Future 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 { Future insertMultipleItem(Map 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 { Future 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 { @override Future 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 { Future updateMultipleItem(Map 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 { Future clearAllData() { return Future.sync(() async { final boxMailbox = await openBox(); - boxMailbox.clear(); + return boxMailbox.clear(); }).catchError((error) { throw error; }); diff --git a/lib/features/caching/recent_search_cache_client.dart b/lib/features/caching/recent_search_cache_client.dart index d73a29496..b5fb7187d 100644 --- a/lib/features/caching/recent_search_cache_client.dart +++ b/lib/features/caching/recent_search_cache_client.dart @@ -11,8 +11,8 @@ class RecentSearchCacheClient extends HiveCacheClient { @override Future 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 { @override Future 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 { @override Future deleteMultipleItem(List 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 { @override Future> 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 { @override Future getItem(String key) { - throw UnimplementedError(); + return Future.sync(() async { + final boxRecent = await openBox(); + return boxRecent.get(key); + }).catchError((error) { + throw error; + }); } @override Future 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 { @override Future insertMultipleItem(Map mapObject) { - throw UnimplementedError(); + return Future.sync(() async { + final boxRecent = await openBox(); + return boxRecent.putAll(mapObject); + }).catchError((error) { + throw error; + }); } @override Future 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 { @override Future 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 { @override Future 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 { @override Future updateMultipleItem(Map mapObject) { - throw UnimplementedError(); + return Future.sync(() async { + final boxRecent = await openBox(); + return boxRecent.putAll(mapObject); + }).catchError((error) { + throw error; + }); } } \ No newline at end of file diff --git a/lib/features/caching/state_cache_client.dart b/lib/features/caching/state_cache_client.dart index cfd1e6dee..bd9b755e3 100644 --- a/lib/features/caching/state_cache_client.dart +++ b/lib/features/caching/state_cache_client.dart @@ -60,7 +60,7 @@ class StateCacheClient extends HiveCacheClient { Future 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 { Future insertMultipleItem(Map 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 { Future 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 { Future deleteMultipleItem(List 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 { Future updateMultipleItem(Map 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 { Future clearAllData() { return Future.sync(() async { final boxState = await openBox(); - boxState.clear(); + return boxState.clear(); }).catchError((error) { throw error; }); diff --git a/lib/features/caching/token_oidc_cache_client.dart b/lib/features/caching/token_oidc_cache_client.dart index 41120defb..c40dadbda 100644 --- a/lib/features/caching/token_oidc_cache_client.dart +++ b/lib/features/caching/token_oidc_cache_client.dart @@ -11,7 +11,7 @@ class TokenOidcCacheClient extends HiveCacheClient { Future 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 { Future 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 { Future insertMultipleItem(Map 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 { @override Future 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 { Future 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 { Future updateMultipleItem(Map mapObject) { return Future.sync(() async { final boxToken = await openBox(); - boxToken.putAll(mapObject); + return boxToken.putAll(mapObject); }).catchError((error) { throw error; });