Last active
August 29, 2015 14:13
-
-
Save 1hakr/340fa402ce522186fb33 to your computer and use it in GitHub Desktop.
parseIgnoreCacheHeaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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