Skip to content

Commit ff1d503

Browse files
Abstracting cache matching (#1341)
* Abstracting cache matching * Updating v1 * Adding copy back.
1 parent 468f68f commit ff1d503

File tree

2 files changed

+78
-58
lines changed

2 files changed

+78
-58
lines changed

docs/index.bs

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
16751675
boolean ignoreSearch = false;
16761676
boolean ignoreMethod = false;
16771677
boolean ignoreVary = false;
1678-
DOMString cacheName;
16791678
};
16801679
</pre>
16811680

@@ -1916,12 +1915,16 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
19161915
<pre class="idl">
19171916
[SecureContext, Exposed=(Window,Worker)]
19181917
interface CacheStorage {
1919-
[NewObject] Promise&lt;any&gt; match(RequestInfo request, optional CacheQueryOptions options);
1918+
[NewObject] Promise&lt;any&gt; match(RequestInfo request, optional MultiCacheQueryOptions options);
19201919
[NewObject] Promise&lt;boolean&gt; has(DOMString cacheName);
19211920
[NewObject] Promise&lt;Cache&gt; open(DOMString cacheName);
19221921
[NewObject] Promise&lt;boolean&gt; delete(DOMString cacheName);
19231922
[NewObject] Promise&lt;sequence&lt;DOMString&gt;&gt; keys();
19241923
};
1924+
1925+
dictionary MultiCacheQueryOptions : CacheQueryOptions {
1926+
DOMString cacheName;
1927+
};
19251928
</pre>
19261929
<!--FIXME(jungkees): set method is not entirely dropped yet. Promise&lt;any&gt; set(DOMString key, Cache val);-->
19271930

@@ -1936,10 +1939,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
19361939

19371940
<dfn method for="CacheStorage"><code>match(|request|, |options|)</code></dfn> method *must* run these steps:
19381941

1939-
1. If |options|.{{CacheQueryOptions/cacheName}} is [=present=], then:
1942+
1. If |options|.{{MultiCacheQueryOptions/cacheName}} is [=present=], then:
19401943
1. Return [=a new promise=] |promise| and run the following substeps [=in parallel=]:
19411944
1. [=map/For each=] |cacheName| → |cache| of the [=relevant name to cache map=]:
1942-
1. If |options|.{{CacheQueryOptions/cacheName}} matches |cacheName|, then:
1945+
1. If |options|.{{MultiCacheQueryOptions/cacheName}} matches |cacheName|, then:
19431946
1. Resolve |promise| with the result of running the algorithm specified in {{Cache/match(request, options)}} method of {{Cache}} interface with |request| and |options| (providing |cache| as thisArgument to the `[[Call]]` internal method of {{Cache/match(request, options)}}.)
19441947
1. Abort these steps.
19451948
1. Resolve |promise| with undefined.
@@ -3187,7 +3190,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31873190
<h3 id="query-cache-algorithm"><dfn>Query Cache</dfn></h3>
31883191

31893192
: Input
3190-
:: |request|, a [=/request=]
3193+
:: |requestQuery|, a [=/request=]
31913194
:: |options|, a {{CacheQueryOptions}} object, optional
31923195
:: |targetStorage|, a [=request response list=], optional
31933196
: Output
@@ -3196,37 +3199,44 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31963199
1. Let |requests| be an empty [=list=].
31973200
1. Let |responses| be an empty [=list=].
31983201
1. Let |resultList| be an empty [=list=].
3199-
1. If |options|.{{CacheQueryOptions/ignoreMethod}} is false and |request|'s [=request/method=] is not \`<code>GET</code>\`, return |resultList|.
3200-
1. Let |cachedURL| and |requestURL| be null.
32013202
1. Let |storage| be null.
32023203
1. If the optional argument |targetStorage| is omitted, set |storage| to the [=relevant request response list=].
32033204
1. Else, set |storage| to |targetStorage|.
32043205
1. [=list/For each=] |requestResponse| of |storage|:
3205-
1. Set |cachedURL| to |requestResponse|'s request's [=request/url=].
3206-
1. Set |requestURL| to |request|'s [=request/url=].
3207-
1. If |options|.{{CacheQueryOptions/ignoreSearch}} is true, then:
3208-
1. Set |cachedURL|'s [=url/query=] to the empty string.
3209-
1. Set |requestURL|'s [=url/query=] to the empty string.
3210-
1. If |cachedURL| [=url/equals=] |requestURL| with the *exclude fragment flag* set, then:
3211-
1. Add a copy of |requestResponse|'s request to |requests|.
3212-
1. Add a copy of |requestResponse|'s response to |responses|.
3213-
1. Let |index| be zero.
3214-
1. For each |cachedResponse| in |responses|:
3215-
1. Let |cachedRequest| be |requests|[|index|].
3216-
1. Increment |index| by one.
3217-
1. If |cachedResponse|'s [=response/header list=] contains no <a>header</a> [=header/named=] \`<code>Vary</code>\`, or |options|.{{CacheQueryOptions/ignoreVary}} is true, then:
3218-
1. [=list/Append=] |cachedRequest|/|cachedResponse| to |resultList|.
3219-
1. [=Continue=].
3220-
1. Let |fieldValues| be the [=list=] containing the elements corresponding to the [=http/field-values=] of the <a>Vary</a> header.
3221-
1. Let |isMatched| be true.
3222-
1. For each |fieldValue| in |fieldValues|:
3223-
1. If |fieldValue| matches "`*`", or the [=combined value=] given |fieldValue| and |cachedRequest|'s [=request/header list=] does not match the [=combined value=] given |fieldValue| and |request|'s [=request/header list=], then:
3224-
1. Set |isMatched| to false.
3225-
1. [=Break=].
3226-
1. If |isMatched| is true, [=list/append=] |cachedRequest|/|cachedResponse| to |resultList|.
3206+
1. Let |cachedRequest| be |requestResponse|'s request.
3207+
1. Let |cachedResponse| be |requestResponse|'s response.
3208+
1. If [=Request Matches Cached Item=] with |requestQuery|, |cachedRequest|, |cachedResponse|, and |options| returns true, then:
3209+
1. Let |requestCopy| be a copy of |cachedRequest|.
3210+
1. Let |responseCopy| be a copy of |cachedResponse|.
3211+
1. Add |requestCopy|/|responseCopy| to |resultList|.
32273212
1. Return |resultList|.
32283213
</section>
32293214

3215+
<section algorithm>
3216+
<h3 id="request-matches-cached-item-algorithm"><dfn export>Request Matches Cached Item</dfn></h3>
3217+
3218+
: Input
3219+
:: |requestQuery|, a [=/request=]
3220+
:: |request|, a [=/request=]
3221+
:: |response|, a [=/response=] or null, optional, defaulting to null
3222+
:: |options|, a {{CacheQueryOptions}} object, optional
3223+
: Output
3224+
:: a boolean
3225+
3226+
1. If |options|.{{CacheQueryOptions/ignoreMethod}} is false and |request|'s [=request/method=] is not \``GET`\`, return false.
3227+
1. Let |queryURL| be |requestQuery|'s [=request/url=].
3228+
1. Let |cachedURL| be |request|'s [=request/url=].
3229+
1. If |options|.{{CacheQueryOptions/ignoreSearch}} is true, then:
3230+
1. Set |cachedURL|'s [=url/query=] to the empty string.
3231+
1. Set |requestURL|'s [=url/query=] to the empty string.
3232+
1. If |queryURL| does not [=url/equal=] |cachedURL| with the *exclude fragment flag* set, then return false.
3233+
1. If |response| is null, |options|.{{CacheQueryOptions/ignoreVary}} is true, or |response|'s [=response/header list=] does not [=header list/contain=] \``Vary`\`, then return true.
3234+
1. Let |fieldValues| be the [=list=] containing the elements corresponding to the [=http/field-values=] of the [=Vary=] header for the [=header/value=] of the [=header=] with [=header/name=] \``Vary`\`.
3235+
1. For each |fieldValue| in |fieldValues|:
3236+
1. If |fieldValue| matches "`*`", or the [=combined value=] given |fieldValue| and |request|'s [=request/header list=] does not match the [=combined value=] given |fieldValue| and |requestQuery|'s [=request/header list=], then return false.
3237+
1. Return true.
3238+
</section>
3239+
32303240
<section algorithm>
32313241
<h3 id="batch-cache-operations-algorithm"><dfn>Batch Cache Operations</dfn></h3>
32323242

docs/v1/index.bs

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
15891589
boolean ignoreSearch = false;
15901590
boolean ignoreMethod = false;
15911591
boolean ignoreVary = false;
1592-
DOMString cacheName;
15931592
};
15941593
</pre>
15951594

@@ -1830,12 +1829,16 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
18301829
<pre class="idl">
18311830
[SecureContext, Exposed=(Window,Worker)]
18321831
interface CacheStorage {
1833-
[NewObject] Promise&lt;any&gt; match(RequestInfo request, optional CacheQueryOptions options);
1832+
[NewObject] Promise&lt;any&gt; match(RequestInfo request, optional MultiCacheQueryOptions options);
18341833
[NewObject] Promise&lt;boolean&gt; has(DOMString cacheName);
18351834
[NewObject] Promise&lt;Cache&gt; open(DOMString cacheName);
18361835
[NewObject] Promise&lt;boolean&gt; delete(DOMString cacheName);
18371836
[NewObject] Promise&lt;sequence&lt;DOMString&gt;&gt; keys();
18381837
};
1838+
1839+
dictionary MultiCacheQueryOptions : CacheQueryOptions {
1840+
DOMString cacheName;
1841+
};
18391842
</pre>
18401843
<!--FIXME(jungkees): set method is not entirely dropped yet. Promise&lt;any&gt; set(DOMString key, Cache val);-->
18411844

@@ -1850,10 +1853,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
18501853

18511854
<dfn method for="CacheStorage"><code>match(|request|, |options|)</code></dfn> method *must* run these steps:
18521855

1853-
1. If |options|.{{CacheQueryOptions/cacheName}} is [=present=], then:
1856+
1. If |options|.{{MultiCacheQueryOptions/cacheName}} is [=present=], then:
18541857
1. Return [=a new promise=] |promise| and run the following substeps [=in parallel=]:
18551858
1. [=map/For each=] |cacheName| → |cache| of the [=relevant name to cache map=]:
1856-
1. If |options|.{{CacheQueryOptions/cacheName}} matches |cacheName|, then:
1859+
1. If |options|.{{MultiCacheQueryOptions/cacheName}} matches |cacheName|, then:
18571860
1. Resolve |promise| with the result of running the algorithm specified in {{Cache/match(request, options)}} method of {{Cache}} interface with |request| and |options| (providing |cache| as thisArgument to the `[[Call]]` internal method of {{Cache/match(request, options)}}.)
18581861
1. Abort these steps.
18591862
1. Resolve |promise| with undefined.
@@ -3033,7 +3036,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
30333036
<h3 id="query-cache-algorithm"><dfn>Query Cache</dfn></h3>
30343037

30353038
: Input
3036-
:: |request|, a [=/request=]
3039+
:: |requestQuery|, a [=/request=]
30373040
:: |options|, a {{CacheQueryOptions}} object, optional
30383041
:: |targetStorage|, a [=request response list=], optional
30393042
: Output
@@ -3042,37 +3045,44 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
30423045
1. Let |requests| be an empty [=list=].
30433046
1. Let |responses| be an empty [=list=].
30443047
1. Let |resultList| be an empty [=list=].
3045-
1. If |options|.{{CacheQueryOptions/ignoreMethod}} is false and |request|'s [=request/method=] is not \`<code>GET</code>\`, return |resultList|.
3046-
1. Let |cachedURL| and |requestURL| be null.
30473048
1. Let |storage| be null.
30483049
1. If the optional argument |targetStorage| is omitted, set |storage| to the [=relevant request response list=].
30493050
1. Else, set |storage| to |targetStorage|.
30503051
1. [=list/For each=] |requestResponse| of |storage|:
3051-
1. Set |cachedURL| to |requestResponse|'s request's [=request/url=].
3052-
1. Set |requestURL| to |request|'s [=request/url=].
3053-
1. If |options|.{{CacheQueryOptions/ignoreSearch}} is true, then:
3054-
1. Set |cachedURL|'s [=url/query=] to the empty string.
3055-
1. Set |requestURL|'s [=url/query=] to the empty string.
3056-
1. If |cachedURL| [=url/equals=] |requestURL| with the *exclude fragment flag* set, then:
3057-
1. Add a copy of |requestResponse|'s request to |requests|.
3058-
1. Add a copy of |requestResponse|'s response to |responses|.
3059-
1. Let |index| be zero.
3060-
1. For each |cachedResponse| in |responses|:
3061-
1. Let |cachedRequest| be |requests|[|index|].
3062-
1. Increment |index| by one.
3063-
1. If |cachedResponse|'s [=response/header list=] contains no <a>header</a> [=header/named=] \`<code>Vary</code>\`, or |options|.{{CacheQueryOptions/ignoreVary}} is true, then:
3064-
1. [=list/Append=] |cachedRequest|/|cachedResponse| to |resultList|.
3065-
1. [=Continue=].
3066-
1. Let |fieldValues| be the [=list=] containing the elements corresponding to the [=http/field-values=] of the <a>Vary</a> header.
3067-
1. Let |isMatched| be true.
3068-
1. For each |fieldValue| in |fieldValues|:
3069-
1. If |fieldValue| matches "`*`", or the [=combined value=] given |fieldValue| and |cachedRequest|'s [=request/header list=] does not match the [=combined value=] given |fieldValue| and |request|'s [=request/header list=], then:
3070-
1. Set |isMatched| to false.
3071-
1. [=Break=].
3072-
1. If |isMatched| is true, [=list/append=] |cachedRequest|/|cachedResponse| to |resultList|.
3052+
1. Let |cachedRequest| be |requestResponse|'s request.
3053+
1. Let |cachedResponse| be |requestResponse|'s response.
3054+
1. If [=Request Matches Cached Item=] with |requestQuery|, |cachedRequest|, |cachedResponse|, and |options| returns true, then:
3055+
1. Let |requestCopy| be a copy of |cachedRequest|.
3056+
1. Let |responseCopy| be a copy of |cachedResponse|.
3057+
1. Add |requestCopy|/|responseCopy| to |resultList|.
30733058
1. Return |resultList|.
30743059
</section>
30753060

3061+
<section algorithm>
3062+
<h3 id="request-matches-cached-item-algorithm"><dfn export>Request Matches Cached Item</dfn></h3>
3063+
3064+
: Input
3065+
:: |requestQuery|, a [=/request=]
3066+
:: |request|, a [=/request=]
3067+
:: |response|, a [=/response=] or null, optional, defaulting to null
3068+
:: |options|, a {{CacheQueryOptions}} object, optional
3069+
: Output
3070+
:: a boolean
3071+
3072+
1. If |options|.{{CacheQueryOptions/ignoreMethod}} is false and |request|'s [=request/method=] is not \``GET`\`, return false.
3073+
1. Let |queryURL| be |requestQuery|'s [=request/url=].
3074+
1. Let |cachedURL| be |request|'s [=request/url=].
3075+
1. If |options|.{{CacheQueryOptions/ignoreSearch}} is true, then:
3076+
1. Set |cachedURL|'s [=url/query=] to the empty string.
3077+
1. Set |requestURL|'s [=url/query=] to the empty string.
3078+
1. If |queryURL| does not [=url/equal=] |cachedURL| with the *exclude fragment flag* set, then return false.
3079+
1. If |response| is null, |options|.{{CacheQueryOptions/ignoreVary}} is true, or |response|'s [=response/header list=] does not [=header list/contain=] \``Vary`\`, then return true.
3080+
1. Let |fieldValues| be the [=list=] containing the elements corresponding to the [=http/field-values=] of the [=Vary=] header for the [=header/value=] of the [=header=] with [=header/name=] \``Vary`\`.
3081+
1. For each |fieldValue| in |fieldValues|:
3082+
1. If |fieldValue| matches "`*`", or the [=combined value=] given |fieldValue| and |request|'s [=request/header list=] does not match the [=combined value=] given |fieldValue| and |requestQuery|'s [=request/header list=], then return false.
3083+
1. Return true.
3084+
</section>
3085+
30763086
<section algorithm>
30773087
<h3 id="batch-cache-operations-algorithm"><dfn>Batch Cache Operations</dfn></h3>
30783088

0 commit comments

Comments
 (0)