cacheIfAvailable method
Retrieve response from the cache if available or fallback to the network.
Implementation
Future<Response> cacheIfAvailable(Request request) async {
_throwOnRequestWithoutCacheKey(request);
/// get cache
final cachedResponse = await cache.read(request.key);
if (cachedResponse != null) {
return cachedResponse;
} else {
/// Get response from network.
/// Send method automatically updates cache.
final networkResponse = await send(request);
return networkResponse;
}
}