summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorFicus Kirkpatrick <ficus@android.com>2015-02-15 17:35:54 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-02-15 17:35:55 +0000
commit2d134b2a0dc521c05c56930a23df1218dc4976a3 (patch)
treefc17378b2024f91eed2c9f70a77404c8c6528cfe /src/main/java/com
parent0cc8d620fe12412f90ba5121bdffb1a4e2f032c2 (diff)
parent8e33d93dc1aae9bb9dbde3b80af8a76ba28f0e19 (diff)
downloadvolley-2d134b2a0dc521c05c56930a23df1218dc4976a3.tar.gz
Merge "Adds Cache-Control "stale-while-revalidate""
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/android/volley/toolbox/HttpHeaderParser.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java b/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java
index e342c9e..da04490 100644
--- a/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java
+++ b/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java
@@ -45,7 +45,9 @@ public class HttpHeaderParser {
long lastModified = 0;
long serverExpires = 0;
long softExpire = 0;
+ long finalExpire = 0;
long maxAge = 0;
+ long staleWhileRevalidate = 0;
boolean hasCacheControl = false;
String serverEtag = null;
@@ -69,6 +71,11 @@ public class HttpHeaderParser {
maxAge = Long.parseLong(token.substring(8));
} catch (Exception e) {
}
+ } else if (token.startsWith("stale-while-revalidate=")) {
+ try {
+ staleWhileRevalidate = Long.parseLong(token.substring(23));
+ } catch (Exception e) {
+ }
} else if (token.equals("must-revalidate") || token.equals("proxy-revalidate")) {
maxAge = 0;
}
@@ -91,16 +98,18 @@ public class HttpHeaderParser {
// is more restrictive.
if (hasCacheControl) {
softExpire = now + maxAge * 1000;
+ finalExpire = softExpire + staleWhileRevalidate * 1000;
} else if (serverDate > 0 && serverExpires >= serverDate) {
// Default semantic for Expire header in HTTP specification is softExpire.
softExpire = now + (serverExpires - serverDate);
+ finalExpire = softExpire;
}
Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
- entry.ttl = entry.softTtl;
+ entry.ttl = finalExpire;
entry.serverDate = serverDate;
entry.lastModified = lastModified;
entry.responseHeaders = headers;