-
Notifications
You must be signed in to change notification settings - Fork 130
enhance(response-cache/cfw-kv): simplify cache init #2238
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
Conversation
🦋 Changeset detectedLatest commit: 40868c0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🚀 Snapshot Release (
|
Package | Version | Info |
---|---|---|
@envelop/response-cache |
6.2.0-alpha-20240528125003-40868c0a |
npm ↗︎ unpkg ↗︎ |
@envelop/response-cache-cloudflare-kv |
1.0.0-alpha-20240528125003-40868c0a |
npm ↗︎ unpkg ↗︎ |
💻 Website PreviewThe latest changes are available as preview in: https://acf91942.envelop.pages.dev |
✅ Benchmark Results
|
Just to let you know, there is another PR (#2237) which also updates the CFW cache plugin. It updates types, so it should not be of a huge impact, I probably can do the rebase for you after merging if you want. |
You can rebase but also keep in mind, my PR removes the need of the type compatibility. So we don't even need to deal with ReadacleStream conflict in that case. |
We are still importing the You mean that the fact we don't take this as a parameter anymore avoid the typing issue in user land ? |
@EmrysMyrddin I believe so but even if not, that is not the main goal of this PR. The main goal is to simplify the usage, move the server definition etc on top, less verbose API etc. |
I still think it can be good to merge the other PR anyway, pinning version could avoid breaking the plugin on updates ? |
@ardatan Is it ok to merge this ? |
Sure you can rebase the conflicts and merge! |
eee91c9
to
3c46a73
Compare
} | ||
return undefined; | ||
}, | ||
return function KVCacheFactory(ctx: TServerContext): Cache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably even warn only once at the start of the function isn't it ?
return function KVCacheFactory(ctx: TServerContext): Cache { | |
return function KVCacheFactory(ctx: TServerContext): Cache { | |
if (!ctx[config.KVName]) { | |
// eslint-disable-next-line no-console | |
console.warn( | |
`Cloudflare KV namespace ${config.KVName} is not available in the server context, cache will be skipped.`, | |
); | |
return { | |
get: () => undefined, | |
set: () => undefined, | |
invalidate: () => undefined, | |
}; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the lifecycle of CF Workers, so I thought it might be added later on after startup. I preferred to check it lazily.
Co-authored-by: Valentin Cocaud <v.cocaud@gmail.com>
This PR introduces the following changes;
cache
parameter accepts a factory function that takes the context and returns the cache implementationSee the changes in the README for details