Can I stop the HTTPResponseCache behaving like a shared cache regarding Cache-Control headers?

I'm trying to use the built-in HTTPResponseCache in my application (making requests through the HTTPURLConnection API), but I'm having problems trying to cache any responses requested with the Authorization header turned on.

The only way to force it to cache the response at all is to explicitly put "public" in the header of the Cache-Control response on the server ( s-maxage can work too, did not try, but explicitly placed private does not lead to caching); but that would mean that any intermediate proxies cache the response to serve other clients, which I don't want.

I understand that the user's cache client caches responses requested by the default Authorization headers or with the private header. It appears that the HTTPResponseCache acts as a shared cache in the way it interprets the headers, not the user's cache. Or is my understanding of caching standards wrong?

Is there any way to make the cache act as the cache of the user's HTTP agent?

This is in my installation code:

 public static void setupCache(Context context, long httpCacheSize){ File httpCacheDir = new File(context.getCacheDir(),"http"); HttpResponseCache.install(httpCacheDir, httpCacheSize); } 

Do I need to change anything here? Or maybe I need to include some user agent data in my queries?

+6
source share
1 answer

Until I found a solution to this particular problem, I worked on my problem, refactoring my HTTP client code to use Volley ( http://developer.android.com/training/volley/index.html ), not HTTPURLConnection. Volley's caching objects are implemented separately for HTTPResponseCache and implement cache control header processing, as expected for the user agent cache.

0
source

All Articles