flcCachedFileLoader<K> function
FileLoader<K>
flcCachedFileLoader<K>({
- required FileLoader<
K> loader, - required FileStore store,
- required FilePath pathProvider(
- K key
Implementation
FileLoader<K> flcCachedFileLoader<K>({
required FileLoader<K> loader,
required FileStore store,
required FilePath Function(K key) pathProvider,
}) {
final cache = Cache<K, Future<Future<Uint8List> Function()>>(
(key) async {
final path = pathProvider(key);
if (!await store.exists(path)) {
final data = await loader(key);
await store.write(path, data);
}
return () => store.read(path);
},
);
return (path) async {
final fn = await cache.get(path);
return await fn();
};
}