middleware icon indicating copy to clipboard operation
middleware copied to clipboard

RFC: Response cache

Open muningis opened this issue 11 months ago • 6 comments

The author should do the following, if applicable

  • [ ] Add tests
  • [ ] Run tests
  • [ ] yarn changeset at the top of this repo and push the changeset
  • [ ] Follow the contribution guide

muningis avatar Feb 27 '25 18:02 muningis

⚠️ No Changeset found

Latest commit: b8b1987f2f56732f31ac413fd78ca78f7ef772a0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Feb 27 '25 18:02 changeset-bot[bot]

@yusukebe Hy, could you check this out please? :) Still very basic, no tests even yet, just to get feeling/idea if there would be interest to continue with this

muningis avatar Mar 04 '25 20:03 muningis

At first glance, I don't think this is needed. We already have the built-in Cache Middleware. If you want to cache just "Response", it's enough to use it.

yusukebe avatar Mar 04 '25 20:03 yusukebe

As per my understanding, that middleware only works on cloudflare an deno, and uses specific cache mechanism. This allows little bit more freedom, for example, by using redis which has TTL (unlike Cache API).

Also, correct me if I'm wrong, but that Cache API helps cache'ing it on Cloudflare/DenoDeploy level, basically "edge/cdn" rather than on server, right?

muningis avatar Mar 05 '25 18:03 muningis

Forgot to mention - this allows to customize cache’ing keys. So for example, if you’re running A/B test, and store A/B tests list in cookie - you can use that cookie to allow to cache page rendered under specific A/B conditions.

Quite niche example, but solution is quite lightweight with provided flexibility.

muningis avatar Mar 06 '25 13:03 muningis

@muningis

Thank you for the explanation! Makes sense.

Also, correct me if I'm wrong, but that Cache API helps cache'ing it on Cloudflare/DenoDeploy level, basically "edge/cdn" rather than on server, right?

Yes. The Cache API is standardized, but you can only use it in particular runtimes like Cloudflare Workers and Deno.

This middleware looks good. Let's go ahead.

yusukebe avatar Mar 07 '25 03:03 yusukebe