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

HTTP Cache API #1051

Open
wants to merge 101 commits into
base: main
Choose a base branch
from
Open

HTTP Cache API #1051

wants to merge 101 commits into from

Conversation

guybedford
Copy link
Member

@guybedford guybedford commented Nov 22, 2024

This implements the HTTP Cache API following the Rust implementation very closely, it is almost a verbatim translation of the Rust SDK semantics, apart from being adapted to the JS fetch API and using async send calls.

This feature uses the HTTP cache APIs only when they are both supported and also when adding the --enable-http-cache CLI argument to the js-compute runtime build command. The plan is to disable this flag for future versions and make it the default, but we want to be careful to ensure adequate testing and to avoid regressions.

Typing uses a variation of #1018 that uses real mutable Request and Response objects instead of relying on a new CandidateResponse object. The Response is effectively a CandidateResponse when it has a CacheEntry handle associated with it. A new error is then thrown when attempting to access the body of one of these response objects to support the CandidateResponse semantics. Effectively the CacheHandle slot being set handles the divergence here.

In the process, we also update new CacheControl('override', { ... opts ... }) to have the new direct override object syntax variation new CacheControl({ ...opts... }) as the override, and we also now support passing just the cache override init options to the cacheOverride fetch option, e.g. like fetch(url, { cacheOverride: { beforeSend () {...} } }).

The fetch implementation is upgraded to use send_async_v2 and the new implementation is very closely based to the Rust implementation which should replicate the former caching logic in its entirety making this mostly a backwards compatible change, pending further testing before unflagging.

Support for the fetch cache option is not implemented here although could now be partially implemented as per #1050, which is effectively unblocked by this landing.

@guybedford guybedford force-pushed the http-cache branch 2 times, most recently from 3f13d65 to f78e621 Compare November 22, 2024 22:02
@guybedford guybedford changed the title Draft proposal for the HTTP Cache API Draft HTTP Cache API Nov 22, 2024
@guybedford guybedford force-pushed the http-cache branch 4 times, most recently from d663577 to d691bf5 Compare November 28, 2024 21:58
@guybedford guybedford changed the title Draft HTTP Cache API HTTP Cache API Nov 28, 2024
@guybedford guybedford force-pushed the http-cache branch 4 times, most recently from 1df917e to 39159e7 Compare December 14, 2024 00:53
@guybedford guybedford marked this pull request as ready for review January 2, 2025 21:30
@guybedford guybedford force-pushed the http-cache branch 2 times, most recently from 56b48a9 to 468d807 Compare January 15, 2025 05:51
@guybedford guybedford force-pushed the http-cache branch 4 times, most recently from 54e6fc8 to 96e00b5 Compare January 22, 2025 22:58
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

Successfully merging this pull request may close these issues.

CacheOverride Simplifications HTTP Cache API: JS SDK
1 participant