Mark cache version to clear cache data

This commit is contained in:
dab246
2023-02-16 12:00:09 +07:00
committed by Dat Vu
parent 5dadd955ce
commit 66e4d6c5d2
7 changed files with 91 additions and 15 deletions
@@ -0,0 +1,33 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/caching/cache_version_client.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class HiveCacheVersionClient extends CacheVersionClient {
final SharedPreferences _sharedPreferences;
final ExceptionThrower _exceptionThrower;
HiveCacheVersionClient(this._sharedPreferences, this._exceptionThrower);
@override
String get versionKey => 'HiveCacheVersion';
@override
Future<int?> getLatestVersion() {
return Future.sync(() {
final latestVersion = _sharedPreferences.getInt(versionKey);
return latestVersion;
}).catchError((error) {
_exceptionThrower.throwException(error);
});
}
@override
Future<bool> storeVersion(int newVersion) {
return Future.sync(() async {
return await _sharedPreferences.setInt(versionKey, newVersion);
}).catchError((error) {
_exceptionThrower.throwException(error);
});
}
}