Sunday, February 11, 2018

Retrofit - Different API responses on different devices

Leave a Comment

The problem exactly like the following I have one api which can provide some data and one apk,

I got my api response with my device and another different old response on the emulator with the same apk!

The emulator response is up to date with the latest changes while the other different response is before the changes.

The app uses retrofit without caching. So what could be the problem?

Request contains only one header (access token) Response contains headers like (ETag, Access-Control-Max-Age) but retrofit should not deal with them as there is no cache at all.

Screen shot from postman : enter image description here

Also when waiting for a while all devices become up to date!

2 Answers

Answers 1

Are you sure with this?

The app uses retrofit without caching

Based on this https://github.com/square/retrofit/issues/678, I think that retrofit (OkHttp inside retrofit) caching your query.

You can change this behavior by 2 ways:

  • add ?_t=TIMESTAMP into your app query url
  • remove 'Access-Control-Max-Age' header from your server response

Answers 2

Or you can create new OkHttp client to retrofit and write something like that:

new OkHttpClient.Builder().cache(null).build(); 

or

Request.cacheControl(CacheControl.FORCE_NETWORK) 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment