-
Notifications
You must be signed in to change notification settings - Fork 544
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
feat(cache): allow setting custom getKey
for defineCachedEventHandler
#744
Conversation
src/runtime/cache.ts
Outdated
getKey: | ||
opts.getKey || | ||
((event) => { | ||
const url = event.req.originalUrl || event.req.url; |
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.
Maybe we can call getKey
inside this function? this way if it returns null, we can fallback to the default key behavior.
We also need to escape invalid chars also in all conditions (including ..
) as they can lead to security issues.
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.
Yes, I think it makes sense to call it inside and fallback to the default; as for the escaping of invalid chars, do you mean escaping them from the returned key?
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.
Yes, to only allow ascii charachters like later regex we have.
@@ -142,11 +146,9 @@ export function defineCachedEventHandler<T = any>( | |||
...opts, | |||
getKey: (event) => { | |||
const key = opts.getKey?.(event) | |||
if (key) { return key } | |||
if (key) { return escapeKey(key) } |
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.
like this? @pi0
getKey
for defineCachedEventHandler
Thanks <3 |
thank you, now I can't wait to get back to work next year and remove all my disgusting hacks, lmao |
π Linked issue
resolves #691
β Type of change
π Description
π Checklist