title: Retrofit 2: Caching doesn't work after cached response expires
body: <p>In my android app I'm using retrofit 2 with bundled okhttp.
  I'm using following code to set the cache</p>
  
  <pre><code>OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder();
  
  File httpCacheDirectory = new File(MyApplication.getInstance().getCacheDir(), "responses");
  Cache cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024);
  httpBuilder.cache(cache);
  
  
  OkHttpClient httpClient = httpBuilder.build();
  
  Retrofit.Builder builder = new Retrofit.Builder().
          baseUrl(ApplicationConstants.BASE_API_URL).
          client(httpClient).
          addConverterFactory(GsonConverterFactory.create(gson));
  </code></pre>
  
  <p>The cache headers are being set on the response from the server side. It caches the files just fine and displays them from the cache until the cached file expires.</p>
  
  <p>The issue is when the cache expires, it can no longer be cached again. This no longer caches or replaces the old cached file. I think it should automatically clean old invalid cache files and replace with new response and cache it.</p>
  
  <p>How do I clear the invalid response and cache the new valid response.</p>
  
  <p>I've been trying for almost two days now, no solution. In fact to me it seems I'm doing everything as per documentation. Is there something else that might be wrong. </p>
  
  <p>Here are my response log from okhttp</p>
  
  <pre><code>D/OkHttp: Connection: keep-alive
  D/OkHttp: Content-Type: application/json; charset=utf-8
  D/OkHttp: Vary: Accept-Encoding
  D/OkHttp: Transfer-Encoding: chunked
  D/OkHttp: Server: Cowboy
  D/OkHttp: X-Frame-Options: SAMEORIGIN
  D/OkHttp: X-Xss-Protection: 1; mode=block
  D/OkHttp: X-Content-Type-Options: nosniff
  D/OkHttp: Date: Tue, 02 Aug 2016 17:39:23 GMT
  D/OkHttp: X-Pagination: {"total":34,"total_pages":2,"first_page":true,"last_page":false,"prev_page":null,"next_page":2,"out_of_range":false}
  D/OkHttp: Cache-Control: max-age=10800, public, no-transform
  D/OkHttp: Etag: W/"4dcf69c9456102fd57666a1dff0eec3a"
  D/OkHttp: X-Request-Id: 1fb917ac-7f77-4c99-8a3b-20d56af9d441
  D/OkHttp: X-Runtime: 0.081711
  D/OkHttp: Via: 1.1 vegur
  </code></pre>
  
  <p>My cache header for json response is below:</p>
  
  <p>Thanks in advance,</p>