Skip to content

Instantly share code, notes, and snippets.

@1hakr
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1hakr/340fa402ce522186fb33 to your computer and use it in GitHub Desktop.
Save 1hakr/340fa402ce522186fb33 to your computer and use it in GitHub Desktop.
parseIgnoreCacheHeaders
public static Cache.Entry parseIgnoreCacheHeaders(NetworkResponse response) {
long now = System.currentTimeMillis();
Map<String, String> headers = response.headers;
long serverDate = 0;
String serverEtag = null;
String headerValue;
headerValue = headers.get("Date");
if (headerValue != null) {
serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
serverEtag = headers.get("ETag");
final long cacheHitButRefreshed = now + 10 * 1000; // in 3 minutes cache will be hit, but also refreshed on background
final long cacheExpired = now + 60 * 1000; // in 24 hours this cache entry expires completely
final long softExpire = cacheHitButRefreshed;
final long ttl = cacheExpired;
Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
entry.ttl = ttl;
entry.serverDate = serverDate;
entry.responseHeaders = headers;
return entry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment