Skip to content

Cache purge stub#6465

Merged
tewaro merged 1 commit into
mainfrom
atewari/purge-jsrpc
Apr 10, 2026
Merged

Cache purge stub#6465
tewaro merged 1 commit into
mainfrom
atewari/purge-jsrpc

Conversation

@tewaro

@tewaro tewaro commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Creates a ctx.cache object with a purge function.

This allows Cache-enabled workers to purge their own cache.
We expose ctx.cache as JSG_RESOURCE_TYPE with the purge function defined
on it, and the types for that function as separate classes. By default
when an IoContext is not present this field is undefined. However it is
designed to be overridden when embedding workerd for actual use with the
provided types.

@tewaro tewaro requested review from a team as code owners March 31, 2026 15:51

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm Bonk, and I've done a quick review of your PR.

This PR adds a ctx.cache stub property to ExecutionContext, delegating to a virtual Worker::Api::getCtxCacheProperty() hook that returns undefined by default.

Issues (highest severity first):

  1. [HIGH] New ctx.cache property is unconditionally exposed with no compat flag or autogate. Adding a new property to every ExecutionContext instance is a behavioral change — it could shadow user-defined cache properties or break code that checks 'cache' in ctx. Other ctx properties (exports, version, abort) are all gated behind compat flags. This needs at minimum a compat flag or autogate for staged rollout.
  2. [MEDIUM] No tests. There are no tests covering the new getCache() path or the getCtxCacheProperty() hook.
  3. [LOW] Missing TypeScript type definition. The JSG_TS_OVERRIDE blocks in JSG_RESOURCE_TYPE don't include cache, so generated TypeScript types won't reflect this property.
  4. [LOW] Comment inaccuracies. Minor comment issues flagged inline.

These comments were generated by an AI code review assistant and may not be perfect. Please use your judgment when evaluating them.

Comment thread src/workerd/api/global-scope.h
Comment thread src/workerd/api/global-scope.h Outdated
Comment thread src/workerd/api/global-scope.c++ Outdated
@ask-bonk

ask-bonk Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully on PR #6465. Here's a summary of the findings:

  1. [HIGH] No compat flag or autogate: The ctx.cache property is unconditionally exposed to all workers. Other ctx properties (exports, version, abort) are all gated behind compat flags. This is a backward-compat risk since it adds a new enumerable property to every ExecutionContext.

  2. [MEDIUM] No tests: No tests cover the new code paths.

  3. [LOW] Missing TypeScript types: The JSG_TS_OVERRIDE blocks don't include cache.

  4. [LOW] Comment inaccuracies: "CacheW-enabled" typo and incorrect reference to IoChannelFactory (should be Worker::Api).

github run

@github-actions

github-actions Bot commented Mar 31, 2026

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@codecov-commenter

codecov-commenter commented Mar 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.81%. Comparing base (1f30941) to head (b4828ae).

Files with missing lines Patch % Lines
src/workerd/api/global-scope.c++ 0.00% 9 Missing ⚠️
src/workerd/io/worker.c++ 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6465      +/-   ##
==========================================
- Coverage   70.82%   70.81%   -0.01%     
==========================================
  Files         435      435              
  Lines      122656   122668      +12     
  Branches    19267    19268       +1     
==========================================
+ Hits        86871    86872       +1     
- Misses      24371    24383      +12     
+ Partials    11414    11413       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tewaro tewaro requested a review from a team as a code owner March 31, 2026 16:44
@tewaro tewaro requested a review from vicb March 31, 2026 16:44
Comment thread src/workerd/api/global-scope.h
@tewaro tewaro force-pushed the atewari/purge-jsrpc branch from 8413fb6 to 5535f5e Compare April 1, 2026 18:12
@danlapid

danlapid commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

@jasnell can you review this PR please, you probably know better than I do the intricacies that are worth watching out for here.

Comment thread src/workerd/api/global-scope.c++ Outdated
Comment thread src/workerd/api/global-scope.h Outdated
Comment thread src/workerd/api/global-scope.h Outdated

@jasnell jasnell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few nits.

@tewaro tewaro force-pushed the atewari/purge-jsrpc branch 5 times, most recently from 9048e42 to 651cbfa Compare April 9, 2026 03:06
Comment thread src/workerd/api/global-scope.h Outdated
Comment thread src/workerd/api/global-scope.h Outdated
Comment thread src/workerd/api/global-scope.c++ Outdated
@tewaro tewaro force-pushed the atewari/purge-jsrpc branch from 651cbfa to a743801 Compare April 10, 2026 03:14
Creates a ctx.cache object with a purge function.

This allows Cache-enabled workers to purge their own cache.
We expose ctx.cache as JSG_RESOURCE_TYPE with the purge function defined
on it, and the types for that function as separate classes. By default
when an IoContext is not present this field is undefined. However it is
designed to be overridden when embedding workerd for actual use with the
provided types.
@tewaro tewaro force-pushed the atewari/purge-jsrpc branch from a743801 to b4828ae Compare April 10, 2026 03:16
@codspeed-hq

codspeed-hq Bot commented Apr 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 13.83%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 69 untouched benchmarks
⏩ 129 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
Encode_ASCII_32[TextEncoder][0/0/32] 3.1 ms 2.7 ms +13.83%

Comparing atewari/purge-jsrpc (b4828ae) with main (1f30941)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@tewaro tewaro enabled auto-merge April 10, 2026 05:00
@tewaro tewaro merged commit 6fc69a6 into main Apr 10, 2026
22 of 23 checks passed
@tewaro tewaro deleted the atewari/purge-jsrpc branch April 10, 2026 06:03
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.

6 participants