saveNewCacheResponse method
Saves the given response
into the corresponding persistent WebCacheDocument.
Implementation
Future<void> saveNewCacheResponse(Response response) async {
final cacheDocument = WebCacheDocument(creationDate: DateTime.now(), headers: response.headers, responseValue: serializeResponseBody(response));
final folder = await getSaveFolder();
final file = await getCacheFile();
if (!await folder.exists()) {
await folder.create(recursive: true);
}
if (!await file.exists()) {
await file.create();
}
final jsonContent = jsonEncode(cacheDocument.toJson());
await file.writeAsString(jsonContent);
}