Hi!
I'm trying to employ HttpResponseCache to cache each HTTP-request sent with HttpURLConnection.
Could somebody tell me why I get hit count always zero?
Usage:
On 2'nd run I have "NOT cached" in console and hit count == 0.
I'm trying to employ HttpResponseCache to cache each HTTP-request sent with HttpURLConnection.
Could somebody tell me why I get hit count always zero?
Code:
HttpResponseCache.getInstalled().getHitCount()
Usage:
Code:
for(int i = 0; i < 2; i++){
try {
HttpURLConnection connection = (HttpURLConnection) new URL("http://www.google.com").openConnection();
connection.setUseCaches(true);
if(i == 1){
try {
connection.addRequestProperty("Cache-Control", "only-if-cached");
InputStream cached = connection.getInputStream();
// the resource was cached! show it
Log.i(TAG, "cached");
} catch (FileNotFoundException e) {
// the resource was not cached
Log.i(TAG, "NOT cached");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}