cacheIfSuccessful static method
void
cacheIfSuccessful({
- required String cacheKey,
- required HttpResponse response,
- 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-----');
});
}
}