Added support for force refresh without caching, using this system on chatList.dart

This commit is contained in:
2023-02-21 14:58:31 +01:00
parent d5179d5e3d
commit 97551738b0
6 changed files with 24 additions and 10 deletions

View File

@ -10,8 +10,9 @@ abstract class RequestCache<T> {
int maxCacheTime;
Function(T) onUpdate;
bool? renew;
RequestCache(this.maxCacheTime, this.onUpdate);
RequestCache(this.maxCacheTime, this.onUpdate, {this.renew = false});
void start(String file, String document) async {
Map<String, dynamic>? tableData = await Localstore.instance.collection(file).doc(document).get();
@ -20,7 +21,7 @@ abstract class RequestCache<T> {
}
if(DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
return;
if(renew == null || !renew!) return;
}
T newValue = await onLoad();