llfbandit / dio_cache_interceptor

Dio HTTP cache interceptor with multiple stores respecting HTTP directives (ETag, Last-Modified, Cache-Control) with options.
https://pub.dev/packages/dio_cache_interceptor
120 stars 70 forks source link

Not working #133

Closed fluxion8 closed 1 year ago

fluxion8 commented 1 year ago

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

fluxion8 commented 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

fluxion8 commented 1 year ago

`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);

  }

) ]);`

fluxion8 commented 1 year ago

Worked with policy: CachePolicy.forceCache,

This is a ridiculous, incomprehensible, clumsy library.

llfbandit commented 1 year ago

Well, read the docs before trying and diying...