Title: [182010] trunk/Source/WebKit2
Revision
182010
Author
[email protected]
Date
2015-03-26 09:21:44 -0700 (Thu, 26 Mar 2015)

Log Message

[WK2][NetworkCache] Compute if a cached response has expired only when actually needed
https://bugs.webkit.org/show_bug.cgi?id=143070

Reviewed by Antti Koivisto.

Compute if a cached response has expired only when actually needed:
- This is not a history navigation
and
- It does not have "Cache-Control: no-cache" header

Previously, we would always determine if the response has expired and
we often end up not using this information.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::responseHasExpired):
(WebKit::NetworkCache::canUse):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (182009 => 182010)


--- trunk/Source/WebKit2/ChangeLog	2015-03-26 15:29:57 UTC (rev 182009)
+++ trunk/Source/WebKit2/ChangeLog	2015-03-26 16:21:44 UTC (rev 182010)
@@ -1,3 +1,22 @@
+2015-03-26  Chris Dumez  <[email protected]>
+
+        [WK2][NetworkCache] Compute if a cached response has expired only when actually needed
+        https://bugs.webkit.org/show_bug.cgi?id=143070
+
+        Reviewed by Antti Koivisto.
+
+        Compute if a cached response has expired only when actually needed:
+        - This is not a history navigation
+        and
+        - It does not have "Cache-Control: no-cache" header
+
+        Previously, we would always determine if the response has expired and
+        we often end up not using this information.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::responseHasExpired):
+        (WebKit::NetworkCache::canUse):
+
 2015-03-26  Zan Dobersek  <[email protected]>
 
         Avoid the Vector<> copy in WebTouchEvent constructor

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (182009 => 182010)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2015-03-26 15:29:57 UTC (rev 182009)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2015-03-26 16:21:44 UTC (rev 182010)
@@ -150,6 +150,25 @@
     return false;
 }
 
+static inline bool responseHasExpired(const WebCore::ResourceResponse& response, std::chrono::milliseconds timestamp)
+{
+    if (response.cacheControlContainsNoCache())
+        return true;
+
+    auto doubleTimeStamp = std::chrono::duration<double>(timestamp);
+    double age = WebCore::computeCurrentAge(response, doubleTimeStamp.count());
+    double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(response, doubleTimeStamp.count());
+
+    bool hasExpired = age > lifetime;
+
+#ifndef LOG_DISABLED
+    if (hasExpired)
+        LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasExpired age=%f lifetime=%f", age, lifetime);
+#endif
+
+    return hasExpired;
+}
+
 static UseDecision canUse(const Entry& entry, const WebCore::ResourceRequest& request)
 {
     if (!verifyVaryingRequestHeaders(entry.varyingRequestHeaders(), request)) {
@@ -157,18 +176,13 @@
         return UseDecision::NoDueToVaryingHeaderMismatch;
     }
 
-    bool allowExpired = cachePolicyAllowsExpired(request.cachePolicy());
-    auto doubleTimeStamp = std::chrono::duration<double>(entry.timeStamp());
-    double age = WebCore::computeCurrentAge(entry.response(), doubleTimeStamp.count());
-    double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(entry.response(), doubleTimeStamp.count());
-    bool isExpired = age > lifetime;
-    // We never revalidate in the case of a history navigation (i.e. allowExpired is true).
-    bool needsRevalidation = !allowExpired && (entry.response().cacheControlContainsNoCache() || isExpired);
+    // We never revalidate in the case of a history navigation (i.e. cachePolicyAllowsExpired() returns true).
+    bool needsRevalidation = !cachePolicyAllowsExpired(request.cachePolicy()) && responseHasExpired(entry.response(), entry.timeStamp());
     if (!needsRevalidation)
         return UseDecision::Use;
 
     bool hasValidatorFields = entry.response().hasCacheValidatorFields();
-    LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasValidatorFields=%d isExpired=%d age=%f lifetime=%f", isExpired, hasValidatorFields, age, lifetime);
+    LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasValidatorFields=%d", hasValidatorFields);
     if (!hasValidatorFields)
         return UseDecision::NoDueToMissingValidatorFields;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to