Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend supported methods #140

Open
FixThisWorld opened this issue Nov 20, 2023 · 4 comments
Open

Extend supported methods #140

FixThisWorld opened this issue Nov 20, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@FixThisWorld
Copy link

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.

@llfbandit llfbandit added the enhancement New feature or request label Nov 21, 2023
@mahmoud-othmane
Copy link

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!

@mahmoud-othmane
Copy link

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!

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,
        ),
      },

@llfbandit
Copy link
Owner

@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.

@mahmoud-othmane
Copy link

Oh okay got it. Thank you! @llfbandit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants