Browse Source

Merge pull request #114 from jld3103/fix/request-manager-cache

neon: Fix request manager loading from cache
pull/115/head
jld3103 2 years ago committed by GitHub
parent
commit
b924f272c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      packages/neon/lib/src/utils/request_manager.dart

10
packages/neon/lib/src/utils/request_manager.dart

@ -37,7 +37,11 @@ class RequestManager {
final key = '$clientID-$k'; final key = '$clientID-$k';
if (cache != null && await cache!.has(key)) { if (cache != null && await cache!.has(key)) {
try {
yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), loading: true); yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), loading: true);
} catch (e) {
debugPrint(e.toString());
}
} }
try { try {
@ -47,8 +51,12 @@ class RequestManager {
} on Exception catch (e) { } on Exception catch (e) {
if (cache != null && await cache!.has(key)) { if (cache != null && await cache!.has(key)) {
debugPrint(e.toString()); debugPrint(e.toString());
yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), error: e); try {
yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), loading: true);
return; return;
} catch (e) {
debugPrint(e.toString());
}
} }
debugPrint(e.toString()); debugPrint(e.toString());
yield Result.error(e); yield Result.error(e);

Loading…
Cancel
Save