feat: cloudflare cache runtime api
resolves #602
TODO: Needs testing
Really smart approach. Honestly i'm not 💯 sure it would be best case of using unstorage (Nitro v3 rather can directly leverage caches API on top of web response handling)
But let's keep both on the track and tested.
If Nitro v3 can do cached event handlers and functions directly via the cache API then I think may not be necessary then 😄
Happy for you to close if Nitro is handling it better.
@RihanArfan any update on this? (have you tested this solution on prod?)
This isn't Cloudflare-specific. It's using the CacheStorage api, which is also supported by other runtimes too
@ascorbic Cloudflare's implementation of the Cache API is slightly different from the web standard - https://developers.cloudflare.com/workers/runtime-apis/cache/#accessing-cache
Most notably, there's no way to list all keys - https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage/keys
@pi0 Unfortunately haven't been able to yet sorry
@RihanArfan is there a way to implement this in a cross-platform way though, that supports runtimes that implement the web standard too
@RihanArfan is there a way to implement this in a cross-platform way though, that supports runtimes that implement the web standard too
Netlify would also be interested in this.
~~@RihanArfan do you remember what is last state of this? could we move it forward?~~ (updated PR with refactors + tests but seems wrangler proxy is not implementing caches API at least out of the box)
@eduardoboucas while making this one generic could take time (or not be possible), if you have time to draft a driver for netlify, i can merge and release.
Codecov Report
:x: Patch coverage is 29.16667% with 51 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 61.83%. Comparing base (70310f9) to head (673b97e).
:warning: Report is 41 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/drivers/cloudflare-cache-binding.ts | 27.14% | 51 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #603 +/- ##
==========================================
+ Coverage 59.99% 61.83% +1.84%
==========================================
Files 42 44 +2
Lines 3657 3962 +305
Branches 590 661 +71
==========================================
+ Hits 2194 2450 +256
- Misses 1460 1509 +49
Partials 3 3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Disabled tests with a manual test for now (works in prod sandbox with using unstorage:// as cache key)
@dario-piotrowicz @petebacondarwin could you please kindly review this PR and confirm if i am not mistaking and wrangler dev proxy does not implement caches API?
Disabled tests with a manual test for now (works in prod sandbox with using
unstorage://as cache key)@dario-piotrowicz @petebacondarwin could you please kindly review this PR and confirm if i am not mistaking and wrangler dev proxy does not implement caches API?
I am not very familiar with this codebase unfortunately, but by quickly skimming through the PR it all seems correct to me 🙂
Regarding the cache not being implemented you're right, we also have an issue for this: https://github.com/cloudflare/workers-sdk/issues/4879 (which refers to getBidingsProxy the old name for getPlatformProxy, I'll update the issue with the correct name) unfortunately this piece of work has never been prioritized (also it being not trivial doesn't help). The fact that we're trying to get more and more code to run natively in our runtime also makes it a bit improbable in my opinion that we can prioritize getPlatformProxy-only features (unless there's a significant demand/motivation for it) 🥲
(PS: Running code inside miniflare should support the caching API... although I just manually checked that and that doesn't seem to work... I'll need to investigate a bit 🤔)
(PS: sorry for the late reply, I only now saw this 🙇)