hurshi / dio-http-cache

http cache lib for Flutter dio like RxCache
Apache License 2.0
274 stars 223 forks source link

Feature to check if data is from cache #27

Closed thangmam closed 4 years ago

thangmam commented 4 years ago

Hi , thanks for the library.I wanted to ask if its possible to know if the response is cached data or not.This way i will be able to notify UI that the data is cached and may not be updated.Thanks

faiyyazs commented 4 years ago

For the time being you can add a custom field say "cached":true in "extra" for each dio request using an interceptor i.e onRequest & for each response i.e onResponse in the interceptor you can update the same field in extra as false.

When the response is from the local cache your onResponse is not called giving you "cached" as true. This is the quickest way I found so far.

thangmam commented 4 years ago

okay , did not think of that.thanks