api and storage restructure

This commit is contained in:
2026-05-05 22:00:07 +02:00
parent 4f796dac2e
commit 9b5a70b285
53 changed files with 318 additions and 460 deletions
+35
View File
@@ -79,3 +79,38 @@ abstract class RequestCache<T extends ApiResponse?> {
Future<T> onLoad();
}
/// Concrete [RequestCache] that delegates the two overrides to functions
/// passed in the constructor. Used to collapse the dozens of one-class-per-
/// endpoint cache files that all just forward to `<Endpoint>().run()` and
/// `<Response>.fromJson(jsonDecode(...))`.
class SimpleCache<T extends ApiResponse?> extends RequestCache<T> {
final Future<T> Function() _loader;
final T Function(Map<String, dynamic> json) _fromJson;
SimpleCache({
required int cacheTime,
required Future<T> Function() loader,
required T Function(Map<String, dynamic> json) fromJson,
void Function(T)? onUpdate,
void Function(T)? onCacheData,
void Function(T)? onNetworkData,
void Function(Exception)? onError,
bool? renew,
}) : _loader = loader,
_fromJson = fromJson,
super(
cacheTime,
onUpdate,
onError: onError ?? RequestCache.ignore,
renew: renew,
onCacheData: onCacheData,
onNetworkData: onNetworkData,
);
@override
Future<T> onLoad() => _loader();
@override
T onLocalData(String json) => _fromJson(jsonDecode(json));
}