Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Batch Cache Operations" contains a parable that confuses me #1724

Open
amn opened this issue Aug 22, 2024 · 1 comment
Open

"Batch Cache Operations" contains a parable that confuses me #1724

amn opened this issue Aug 22, 2024 · 1 comment

Comments

@amn
Copy link

amn commented Aug 22, 2024

https://w3c.github.io/ServiceWorker/#batch-cache-operations specifies the following step 4.2.3 under "Output":

If the result of running Query Cache with operation’s request, operation’s options, and addedItems is not empty, throw an "InvalidStateError" DOMException.

I don't understand how would this be correct for a "put" operation? To explain my confusion, I'd expect querying of the cache for which put method has been called, to maybe contain a cache hit for a matching request, meaning the "query cache" procedure may return a non-empty list (if equivalent request was there). Why should the implementation throw an InvalidStateError then? Or am I reading the entire parable in wrong context? The later step 4.2.6.6 instructs to run the "query cache" procedure again:

Set requestResponses to the result of running Query Cache with operation’s request.

Doesn't the above read more or less exactly like 4.2.3, while the latter already expects any result (an empty or non-empty list) while the former would have thrown had the cache querying returned a non-empty list?

I must be reading the spec. wrong, but I just can't seem to squint my eyes the right way to see if I can make sense of the above for my part.

@mkruisselbrink
Copy link
Collaborator

In step 4.2.3 "addedItems" is the last argument to query cache; this means that rather than querying the actual cache we're looking for matches in the requests/responses that were stored due to other put operations in the same batch. I.e. if that query cache returns a non-empty result there must be duplicate requests in the batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants