Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. if reponseCode == 304:
  2. body = <getDataFromCache>
  3.  
  4. OkHttpClient client = new OkHttpClient();
  5.  
  6. File cacheDirectory = new File(context.getCacheDir(), "responses");
  7.  
  8. Cache cache = null;
  9. try {
  10. cache = new Cache(cacheDirectory, 10 * 1024 * 1024); // 10M
  11. client.setCache(cache);
  12. } catch (IOException e) {
  13. Log.e("AbstractFeedIntentService", "Could not create http cache", e);
  14. }
  15.  
  16. Request.Builder requestBuilder = new Request.Builder();
  17. requestBuilder.url(url);
  18. Request request = requestBuilder.build();
  19.  
  20. Call call = client.newCall(request);
  21. Response response = call.execute();
  22.  
  23. // if code==304, does the response contain the data from the cache. If not, how to get it?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement