Open FixThisWorld opened 11 months ago
In addition to the above, and I'm not sure if the feature already exists, but anyway, it is good if we have an option to skip the caching for a specific route/endpoint. Basically, I need to be able to cache all the GET requests of the app except for a list of defined endpoints. This can be added to _shouldSkip()
function as well, so you can accept a list like final List<String> skipForRoutes
, and use this list to see which request to skip the caching for. Thank you!
In addition to the above, and I'm not sure if the feature already exists, but anyway, it is good if we have an option to skip the caching for a specific route/endpoint. Basically, I need to be able to cache all the GET requests of the app except for a list of defined endpoints. This can be added to
_shouldSkip()
function as well, so you can accept a list likefinal List<String> skipForRoutes
, and use this list to see which request to skip the caching for. Thank you!
I might have found a way to go around this, but it seems like hack and not a straightforward solution, but I think it works.
Basically, in the extra pass the policy you need for the specific request with a key @cache_options@
, which is defined as follows in the package:
// Key to retrieve options from request
static const _extraKey = '@cache_options@';
In my app I do this:
extra: {
"@cache_options@": currentCacheOptions.copyWith(
policy: CachePolicy.noCache,
),
},
@mahmoud-othmane you can do this explicitly for each route. This option is available like shown in the readme.
response = await dio.get('https://www.foo.com',
options: options.copyWith(policy: CachePolicy.noCache).toOptions(),
);
This way allows to cache every routes but those you've chosen or you can invert it by specifying CachePolicy.noCache
by default.
Oh okay got it. Thank you! @llfbandit
Currently, only GET requests seem to be handled and optionally POST methods, if allowPostMethod == true. I suggest replacing allowPostMethod with allowedMethods: Set, so the user can configure which methods should be cached. As HTTP is used e.g. for WebDAV, that set may even include non-standard HTTP methods like PROPFIND, so just hardcoding all HTTP methods seems too restrictive to me. This should be a minor change in the _shouldSkip() function.