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
119 stars 70 forks source link

Async requests are not being cached #135

Closed oSumAtrIX closed 1 year ago

oSumAtrIX commented 1 year ago

This issue may not belong in this repo but in DIO.

Issue

The cache interceptor saves the response to the cache in the onResponse implementation. When I make 2 identical requests asynchronously but do not read the response yet, both requests will not be caught by the cache. I assume the reason for this is that the 2 requests were made at the time when the cache was not present, because onResponse has not been called yet.

Observations

Reproduction

You can reproduce this issue on our repository: https://github.com/revanced/revanced-manager.

llfbandit commented 1 year ago

QueuedInterceptorsWrapper may help to resolve this. The original issue https://github.com/cfug/dio/issues/590

Here's an example (untested):

    final cache = DioCacheInterceptor(options: cacheOptions);

    dio = Dio()
      ..interceptors.add(
        QueuedInterceptorsWrapper(
          onRequest: cache.onRequest,
          onResponse: cache.onResponse,
          onError: cache.onError,
        ),
      );
oSumAtrIX commented 1 year ago

Unfortunately, this had no effect. But I assume this is the wrong repository. Thanks.