cacheIfSuccessful static method

void cacheIfSuccessful({
  1. required String cacheKey,
  2. required HttpResponse response,
  3. required Duration ttl,
})

Caches a response if it represents a success (2xx).

Implementation

static void cacheIfSuccessful({
  required String cacheKey,
  required HttpResponse<dynamic> response,
  required Duration ttl,
}) {
  if (response.isSuccess) {
    // Fire-and-forget for better performance
    HiveService.cacheResponse(
      key: cacheKey,
      response: response,
      ttlInMilliSeconds: ttl.inMilliseconds,
    ).catchError((e) {
      debugPrint('----HttpService: Cache write error: $e-----');
    });
  }
}