loadFileCacheResource method
Implementation
Future<dynamic> loadFileCacheResource({required String url,Function? errorFunction,String? downloadPath}) async {
dynamic resource;
try {
_log("Loading cache resource for url " + url + "...");
String localPath = "";
if (downloadPath != null) {
localPath = downloadPath;
} else {
localPath = await Simplify.rootAppDirectoryPath + "/cache/" + url;
}
localPath = localPath.replaceAll("://", "/");
File cacheFile = new File(localPath);
if (!await cacheFile.exists()) {
_log("Cache File does not exist. Attempting download...");
await WebServiceHelper.downloadFile(url: url, downloadPath: localPath);
_log("Downloaded cache file.");
}
_log("Reading cache file...");
resource = await cacheFile.readAsBytes();
} catch (ex,stack) {
_log(Simplify.getExceptionMessage(ex,stack: stack));
if (errorFunction != null) {
errorFunction(Simplify.getExceptionMessage(ex,stack: stack));
}
}
return resource;
}