Reputation: 43
I'm working on an Android App, where i'm using Retrofit to communicate with a rest API. This API provides a login, to get X Auth Tokens. I have an interceptor to set this tokens for every request like this:
@Override
public void intercept(RequestFacade request) {
request.addHeader("X-Auth-SOFTTOKEN", softToken);
request.addHeader("X-Auth-HARDTOKEN", hardToken);
request.addHeader("X-Auth-USER", username);
}
I can observe a strange behaviour, where i get Cached responses for the old User, although the X Auth Tokens are different and i should get the response for the new logged in user.
If i add this piece of code to my rest API interface methods, it works.
@Headers("Cache-Control: no-cache")
I can't find any hints if this is expected behaviour or not. I thought the cache should only beeing triggered, if the request is exactly the same.
Upvotes: 1
Views: 484
Reputation: 2664
Have a look at this answer: https://stackoverflow.com/a/35993722/3964585 and from there also http RFC - https://www.rfc-editor.org/rfc/rfc7231#section-7.1.4
In short - caches have to take headers into consideration when server indicates so with "Vary" header. Alternative way for server is to use Cache-control header directives.
Seems that in your case server is returning incorrect responses. If you can, fix that, if not you can not use http cache.
Upvotes: 2