I\'ve been using in my app HttpResponseCache successfully, but when my phone updated to Lollipop I realized that HttpResponseCache now never get \"hit\", always do the netwo
After having this problem for days I ran into this issue. It is fixed again in Marshmallow.
It is a bug in lollipop where the Vary - > Accept-Encoding header breaks the cache because Accept-Encoding gets filled in by default but not written away.
Here is a link to the issue:
https://code.google.com/p/android/issues/detail?id=162475
The fix is to set the Accept-Encoding explicitly:
Accept-Encoding -> gzip
or
Accept-Encoding -> identity
On the reading side you have to add this to the reading of the input stream:
String encoding = urlConnection.getHeaderField("Content-Encoding");
boolean gzipped = encoding!=null && encoding.toLowerCase().contains("gzip");
Inputstream inputStream;
if(gzipped)
inputStream = new GZIPInputStream(urlConnection.getInputStream());
else
inputstream = urlConnection.getInputStream();
I've had similar problem. I was expecting images to be cached but they weren't.
What turned out to be the problem was that I was not closing InputStream
after it being read into a Bitmap.
Your fetchInputStream
returns an InputStream that it got from http connection, make sure you close it properly.
The android http cache will not save a resource until you close the connection's InputStream
.