-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: [EXT-3586] add default cache #41
Conversation
src/keys/get-management-token.ts
Outdated
@@ -16,6 +16,8 @@ export interface GetManagementTokenOptions { | |||
reuseToken?: boolean | |||
} | |||
|
|||
const defaultCache = new NodeCache() |
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.
What about
let defaultCache: NodeCache;
export const getManagementToken = (privateKey: string, opts: GetManagementTokenOptions) => {
if (opts.reuseToken) {
defaultCache = new NodeCache();
}
...
So we don't over-allocate if it's not needed. We could also cleanup createGetManagementToken
at that point
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 that makese sense. I changed it in that way and then removed the assignment in the createGetManagementToken
as this is not needed anymore. Let me know if that is what you meant with cleanup :D
opts | ||
) | ||
if (opts.reuseToken || opts.reuseToken === undefined) { | ||
defaultCache = new NodeCache() |
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 am a bit confused by this. Doesn't it mean that we are initialising the cache each time you a user tries gets a token?
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 you are right, I added a check that this only happens once
if ((opts.reuseToken || opts.reuseToken === undefined) && !defaultCache) { | ||
defaultCache = new NodeCache() | ||
} | ||
return createGetManagementToken( |
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 guess we should now ask why this function even exists. We could just inline the createGetManagementToken
into this function, and it probably makes the code slightly easier to follow. I don't think we need to do it in this PR though.
## [2.0.1](v2.0.0...v2.0.1) (2022-03-11) ### Bug Fixes * [EXT-3586] add default cache ([#41](#41)) ([420cdfb](420cdfb))
🎉 This PR is included in version 2.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fixes #40