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

How to delete all cached data with the same API but different parameters (such as data loaded with pagination) from the cache? #150

Closed andrew2558 closed 7 months ago

andrew2558 commented 7 months ago

if pagination is used to load data, the API requests are like this: getdata?page=1, getdata?page=2, and so on. How can we delete the cached data with the same API but different parameters, so that subsequent requests for the same API do not use the cache but fetch data from the backend instead?

llfbandit commented 7 months ago

I'm not sure to understand fully your request. You can access directly to your store and handle the deletion.

Please use discussion feature for such topics.

andrew2558 commented 7 months ago

I'm sorry, I can't see the discussion tag.

For multiple requests like the following: https://xxx.com/api/getdata?page=1 https://xxx.com/api/getdata?page=2 https://xxx.com/api/getdata?page=3 These requests are for the same API, with only different parameters. The most typical example is loading paginated data. If all of the above requests have been cached locally, is there a way to delete all the cache for the API "https://xxx.com/api/getdata" (ignoring request parameters and focusing only on the request API), so that the next time this API is requested, the data is fetched from the backend instead of the cache? The specific scenario is: Loading data from multiple pages, but the user deletes some data items, causing changes in the original data pages. Therefore, fetching data again needs to be done from the backend and not from the cache (the cached data is from before the deletion).

llfbandit commented 7 months ago

Read the documentation for CacheStore, there's deleteFromPath that should do it.