diff --git a/lib/features/caching/authentication_info_cache_client.dart b/lib/features/caching/authentication_info_cache_client.dart new file mode 100644 index 000000000..b98d22994 --- /dev/null +++ b/lib/features/caching/authentication_info_cache_client.dart @@ -0,0 +1,131 @@ +import 'package:hive/hive.dart'; +import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart'; +import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart'; + +class AuthenticationInfoCacheClient extends HiveCacheClient { + + @override + String get tableName => "AuthenticationInfoCache"; + + @override + Future clearAllData() { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.clear(); + }).catchError((error) { + throw error; + }); + } + + @override + Future deleteItem(String key) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.delete(key); + }).catchError((error) { + throw error; + }); + } + + @override + Future deleteMultipleItem(List listKey) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.deleteAll(listKey); + }).catchError((error) { + throw error; + }); + } + + @override + Future> getAll() { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.values.toList(); + }).catchError((error) { + throw error; + }); + } + + @override + Future getItem(String key) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.get(key); + }).catchError((error) { + throw error; + }); + } + + @override + Future insertItem(String key, AuthenticationInfoCache newObject) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.put(key, newObject); + }).catchError((error) { + throw error; + }); + } + + @override + Future insertMultipleItem(Map mapObject) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.putAll(mapObject); + }).catchError((error) { + throw error; + }); + } + + @override + Future isExistItem(String key) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.containsKey(key); + }).catchError((error) { + throw error; + }); + } + + @override + Future isExistTable() { + return Future.sync(() async { + return Hive.boxExists(tableName); + }).catchError((error) { + throw error; + }); + } + + @override + Future> openBox() async { + return Future.sync(() async { + final encryptionKey = await HiveCacheConfig.getEncryptionKey(); + return Hive.openBox( + tableName, + encryptionCipher: HiveAesCipher(encryptionKey!)); + }).catchError((error) { + throw error; + }); + } + + @override + Future updateItem(String key, AuthenticationInfoCache newObject) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.put(key, newObject); + }).catchError((error) { + throw error; + }); + } + + @override + Future updateMultipleItem(Map mapObject) { + return Future.sync(() async { + final boxAuthenticationInfo = await openBox(); + return boxAuthenticationInfo.putAll(mapObject); + }).catchError((error) { + throw error; + }); + } +} \ No newline at end of file