Closed fluxion8 closed 1 year ago
I tried with custom key builder nothing
Drift: Sent DELETE FROM "DioCache" WHERE "priority" <= ? AND "maxStale" <= ?; with args [2, 1695647998] I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [http://192.168.1.103/user] I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [http://192.168.1.103/groupchat] I/flutter (13798): http://192.168.1.103/user I/flutter (13798): http://192.168.1.103/groupchat I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [http://192.168.1.103/user] I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [http://192.168.1.103/groupchat] I/flutter (13798): DioException [unknown]: null I/flutter (13798): Error: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101), address = 192.168.1.103, port = 80 I/flutter (13798): DioException [unknown]: null I/flutter (13798): Error: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101), address = 192.168.1.103, port = 80
`final options = CacheOptions( // A default store is required for interceptor. store: cacheStore,
// All subsequent fields are optional.
// Default. policy: CachePolicy.request, // Returns a cached response on error but for statuses 401 & 403. // Also allows to return a cached response on network errors (e.g. offline usage). // Defaults to [null]. hitCacheOnErrorExcept: [], // Overrides any HTTP directive to delete entry past this duration. // Useful only when origin server has no cache config or custom behaviour is desired. // Defaults to [null]. maxStale: const Duration(days: 7), keyBuilder: (request) { print(request.uri.toString()); return request.uri.toString(); }, // Default. Allows 3 cache sets and ease cleanup. priority: CachePriority.normal, // Default. Body and headers encryption with your own algorithm. cipher: null, // Default. Key builder to retrieve requests.
// Default. Allows to cache POST requests. // Overriding [keyBuilder] is strongly recommended when [true]. allowPostMethod: false, );
Dio dio = Dio(BaseOptions(baseUrl: url,headers: {"Authorization":"Bearer ${storage.token}"},connectTimeout: const Duration(seconds: 10)))..interceptors.addAll([ DioCacheInterceptor(options: options), InterceptorsWrapper(
onError: (DioException err, ErrorInterceptorHandler handler){
//print(err.message);
if(err.response != null){
print(err.response!.data);
// if(err.response!.statusCode==401){
// storage.saveToken(null);
// loginStore.user = UserModel.fromJsonMap({});
// }
}
//print('hata');
handler.next(err);
}
) ]);`
Worked with
policy: CachePolicy.forceCache,
This is a ridiculous, incomprehensible, clumsy library.
Well, read the docs before trying and diying...
I tried everything but not working. Hive and dbcache nothing. Dio trying to request from network.
Drift: Sent DELETE FROM "DioCache" WHERE "priority" <= ? AND "maxStale" <= ?; with args [2, 1695647790] I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [a43f17a1-1e1c-5c3a-a8e7-d630bb73e16f] I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [479def4a-fe17-5651-9463-b8d906644f30] I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [a43f17a1-1e1c-5c3a-a8e7-d630bb73e16f] I/flutter (13798): Drift: Sent SELECT * FROM "DioCache" WHERE "cacheKey" = ? LIMIT 1; with args [479def4a-fe17-5651-9463-b8d906644f30] I/flutter (13798): DioException [unknown]: null I/flutter (13798): Error: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101), address = 192.168.1.103, port = 80 I/flutter (13798): DioException [unknown]: null I/flutter (13798): Error: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101), address = 192.168.1.103, port = 80