skex
skex

Reputation: 49

Why is it considered dangerous to overwrite cache control headers?

I am using Retrofit/OkHTTP to consume a REST API which doesn't provide proper cache headers. In order to work around this, I've written a cache interceptor which will add cache control headers to the response.

I have seen in multiple places this is considered dangerous, for example the okhttp recipe for this has the following comment:

/** Dangerous interceptor that rewrites the server's cache-control header. */

(source)

Why exactly is this considered to be dangerous? I'd like to understand the risks of doing this.

Upvotes: 0

Views: 87

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40593

You're making decisions on the client that should instead be made on the server. The risk is that the client ends up caching something it shouldn't, which will result in stale data being returned.

Upvotes: 1

Related Questions