Changeset 211288 in webkit


Ignore:
Timestamp:
Jan 27, 2017 10:44:18 AM (7 years ago)
Author:
Antti Koivisto
Message:

Implement Cache-control: immutable
https://bugs.webkit.org/show_bug.cgi?id=167497

Reviewed by Chris Dumez.

Source/WebCore:

Cache-control value 'immutable' indicates that a subresource does not change and so does not need to be
revalidated on a normal reload. This can significantly speed up reloads and reduce network traffic.

It is has been implemented in Firefox and is already used by Facebook.

https://tools.ietf.org/html/draft-mcmanus-immutable-00
https://hacks.mozilla.org/2017/01/using-immutable-caching-to-speed-up-the-web/

This patch implements Cache-control: immutable for memory cache only. A disk cache implementation
doesn't seem necessary as the resource is basically always expected to be in memory cache on reload.

Immutable is only supported for https as suggested by the draft specification (and Gecko implementation).

Test: http/tests/cache/cache-control-immutable-http.html

http/tests/cache/cache-control-immutable-https.html

  • loader/cache/CachedResource.cpp:

(WebCore::CachedResource::makeRevalidationDecision):

On normal reloads (CachePolicyRevalidate) of https resources check for 'Cache-control: immutable'.
If the resource is not expired don't revalidate it.

  • platform/network/CacheValidation.cpp:

(WebCore::parseCacheControlDirectives):

  • platform/network/CacheValidation.h:
  • platform/network/ResourceResponseBase.cpp:

(WebCore::ResourceResponseBase::cacheControlContainsImmutable):

  • platform/network/ResourceResponseBase.h:

LayoutTests:

  • http/tests/cache/cache-control-immutable-http-expected.txt: Added.
  • http/tests/cache/cache-control-immutable-http.html: Added.
  • http/tests/cache/cache-control-immutable-https-expected.txt: Added.
  • http/tests/cache/cache-control-immutable-https.html: Added.
  • http/tests/cache/resources/cache-control-immutable.js: Added.
  • http/tests/cache/resources/iframe-with-script.cgi: Added.
Location:
trunk
Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r211284 r211288  
     12017-01-27  Antti Koivisto  <antti@apple.com>
     2
     3        Implement Cache-control: immutable
     4        https://bugs.webkit.org/show_bug.cgi?id=167497
     5
     6        Reviewed by Chris Dumez.
     7
     8        * http/tests/cache/cache-control-immutable-http-expected.txt: Added.
     9        * http/tests/cache/cache-control-immutable-http.html: Added.
     10        * http/tests/cache/cache-control-immutable-https-expected.txt: Added.
     11        * http/tests/cache/cache-control-immutable-https.html: Added.
     12        * http/tests/cache/resources/cache-control-immutable.js: Added.
     13        * http/tests/cache/resources/iframe-with-script.cgi: Added.
     14
    1152017-01-26  Ryan Haddad  <ryanhaddad@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r211286 r211288  
     12017-01-27  Antti Koivisto  <antti@apple.com>
     2
     3        Implement Cache-control: immutable
     4        https://bugs.webkit.org/show_bug.cgi?id=167497
     5
     6        Reviewed by Chris Dumez.
     7
     8        Cache-control value 'immutable' indicates that a subresource does not change and so does not need to be
     9        revalidated on a normal reload. This can significantly speed up reloads and reduce network traffic.
     10
     11        It is has been implemented in Firefox and is already used by Facebook.
     12
     13        https://tools.ietf.org/html/draft-mcmanus-immutable-00
     14        https://hacks.mozilla.org/2017/01/using-immutable-caching-to-speed-up-the-web/
     15
     16        This patch implements Cache-control: immutable for memory cache only. A disk cache implementation
     17        doesn't seem necessary as the resource is basically always expected to be in memory cache on reload.
     18
     19        Immutable is only supported for https as suggested by the draft specification (and Gecko implementation).
     20
     21        Test: http/tests/cache/cache-control-immutable-http.html
     22              http/tests/cache/cache-control-immutable-https.html
     23
     24        * loader/cache/CachedResource.cpp:
     25        (WebCore::CachedResource::makeRevalidationDecision):
     26
     27            On normal reloads (CachePolicyRevalidate) of https resources check for 'Cache-control: immutable'.
     28            If the resource is not expired don't revalidate it.
     29
     30        * platform/network/CacheValidation.cpp:
     31        (WebCore::parseCacheControlDirectives):
     32        * platform/network/CacheValidation.h:
     33        * platform/network/ResourceResponseBase.cpp:
     34        (WebCore::ResourceResponseBase::cacheControlContainsImmutable):
     35        * platform/network/ResourceResponseBase.h:
     36
    1372017-01-27  Youenn Fablet  <youennf@gmail.com>
    238
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r211248 r211288  
    749749
    750750    case CachePolicyReload:
     751        return RevalidationDecision::YesDueToCachePolicy;
     752
    751753    case CachePolicyRevalidate:
     754        if (m_response.cacheControlContainsImmutable() && m_response.url().protocolIs("https")) {
     755            if (isExpired())
     756                return RevalidationDecision::YesDueToExpired;
     757            return RevalidationDecision::No;
     758        }
    752759        return RevalidationDecision::YesDueToCachePolicy;
    753760
  • trunk/Source/WebCore/platform/network/CacheValidation.cpp

    r209924 r211288  
    317317                if (ok)
    318318                    result.maxStale = duration_cast<microseconds>(duration<double>(maxStale));
    319             }
     319            } else if (equalLettersIgnoringASCIICase(directives[i].first, "immutable"))
     320                result.immutable = true;
    320321        }
    321322    }
  • trunk/Source/WebCore/platform/network/CacheValidation.h

    r208985 r211288  
    6767    bool noStore { false };
    6868    bool mustRevalidate { false };
     69    bool immutable { false };
    6970};
    7071WEBCORE_EXPORT CacheControlDirectives parseCacheControlDirectives(const HTTPHeaderMap&);
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp

    r209403 r211288  
    426426    return m_cacheControlDirectives.mustRevalidate;
    427427}
     428   
     429bool ResourceResponseBase::cacheControlContainsImmutable() const
     430{
     431    if (!m_haveParsedCacheControlHeader)
     432        parseCacheControlDirectives();
     433    return m_cacheControlDirectives.immutable;
     434}
    428435
    429436bool ResourceResponseBase::hasCacheValidatorFields() const
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.h

    r210835 r211288  
    120120   
    121121    // These functions return parsed values of the corresponding response headers.
    122     // NaN means that the header was not present or had invalid value.
    123122    WEBCORE_EXPORT bool cacheControlContainsNoCache() const;
    124123    WEBCORE_EXPORT bool cacheControlContainsNoStore() const;
    125124    WEBCORE_EXPORT bool cacheControlContainsMustRevalidate() const;
     125    WEBCORE_EXPORT bool cacheControlContainsImmutable() const;
    126126    WEBCORE_EXPORT bool hasCacheValidatorFields() const;
    127127    WEBCORE_EXPORT std::optional<std::chrono::microseconds> cacheControlMaxAge() const;
Note: See TracChangeset for help on using the changeset viewer.