refactor(cache): centralize non-fatal writes
This commit is contained in:
@@ -723,11 +723,7 @@ mixin MediaServerCacheMixin implements MediaServerClient {
|
|||||||
try {
|
try {
|
||||||
final response = await networkCall();
|
final response = await networkCall();
|
||||||
if (cacheResponse) {
|
if (cacheResponse) {
|
||||||
try {
|
await _putCacheResponse(cacheKey, response.data);
|
||||||
await _putCacheResponse(cacheKey, response.data);
|
|
||||||
} catch (e, st) {
|
|
||||||
appLogger.w('Cache write failed for $cacheKey', error: e, stackTrace: st);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return parseResponse(response);
|
return parseResponse(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -754,20 +750,20 @@ mixin MediaServerCacheMixin implements MediaServerClient {
|
|||||||
if (isOfflineMode) return null;
|
if (isOfflineMode) return null;
|
||||||
final response = await networkCall();
|
final response = await networkCall();
|
||||||
if (cacheResponse) {
|
if (cacheResponse) {
|
||||||
try {
|
await _putCacheResponse(cacheKey, response.data);
|
||||||
await _putCacheResponse(cacheKey, response.data);
|
|
||||||
} catch (e, st) {
|
|
||||||
appLogger.w('Cache write failed for $cacheKey', error: e, stackTrace: st);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return parseResponse(response);
|
return parseResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _putCacheResponse(String cacheKey, dynamic data) async {
|
Future<void> _putCacheResponse(String cacheKey, dynamic data) async {
|
||||||
if (data is Map<String, dynamic>) {
|
try {
|
||||||
await cache.put(ServerId(cacheServerId), cacheKey, data);
|
if (data is Map<String, dynamic>) {
|
||||||
} else if (data != null) {
|
await cache.put(ServerId(cacheServerId), cacheKey, data);
|
||||||
appLogger.w('Unexpected response type for $cacheKey: ${data.runtimeType}');
|
} else if (data != null) {
|
||||||
|
appLogger.w('Unexpected response type for $cacheKey: ${data.runtimeType}');
|
||||||
|
}
|
||||||
|
} catch (e, st) {
|
||||||
|
appLogger.w('Cache write failed for $cacheKey', error: e, stackTrace: st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user