Finish KeyToken operations
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/models/channel.dart';
|
||||
import 'package:simplecloudnotifier/models/keytoken.dart';
|
||||
import 'package:simplecloudnotifier/models/scn_message.dart';
|
||||
import 'package:simplecloudnotifier/settings/app_settings.dart';
|
||||
|
||||
@@ -57,4 +59,21 @@ class SCNDataCache {
|
||||
|
||||
return cacheMessages;
|
||||
}
|
||||
|
||||
Future<KeyToken> getOrQueryTokenByValue(String uid, String tokVal) async {
|
||||
final cache = Hive.box<KeyToken>('scn-keytoken-value-cache');
|
||||
|
||||
final cacheVal = cache.get(tokVal);
|
||||
if (cacheVal != null) {
|
||||
print('[SCNDataCache] Found Token(${tokVal}) in cache');
|
||||
return Future.value(cacheVal);
|
||||
}
|
||||
|
||||
final tok = await APIClient.getKeyTokenByToken(uid, tokVal);
|
||||
|
||||
print('[SCNDataCache] Queried Token(${tokVal}) from API');
|
||||
await cache.put(tokVal, tok);
|
||||
|
||||
return tok;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user