Skip to content
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

Merged
merged 3 commits into from
Mar 11, 2022
Merged

fix: [EXT-3586] add default cache #41

merged 3 commits into from
Mar 11, 2022

Conversation

loweisz
Copy link
Contributor

@loweisz loweisz commented Mar 7, 2022

fixes #40

@@ -16,6 +16,8 @@ export interface GetManagementTokenOptions {
reuseToken?: boolean
}

const defaultCache = new NodeCache()
Copy link
Contributor

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

Copy link
Contributor Author

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

@loweisz loweisz requested a review from shikaan March 9, 2022 15:36
@loweisz loweisz marked this pull request as ready for review March 9, 2022 15:36
@loweisz loweisz requested a review from a team as a code owner March 9, 2022 15:36
@loweisz loweisz changed the title fix: add default cache fix: [EXT-3586] add default cache Mar 9, 2022
opts
)
if (opts.reuseToken || opts.reuseToken === undefined) {
defaultCache = new NodeCache()
Copy link
Contributor

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?

Copy link
Contributor Author

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

@loweisz loweisz requested a review from Jwhiles March 10, 2022 13:40
if ((opts.reuseToken || opts.reuseToken === undefined) && !defaultCache) {
defaultCache = new NodeCache()
}
return createGetManagementToken(
Copy link
Contributor

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.

@loweisz loweisz merged commit 420cdfb into master Mar 11, 2022
@loweisz loweisz deleted the fix-cache branch March 11, 2022 08:44
ghost pushed a commit that referenced this pull request Mar 11, 2022
## [2.0.1](v2.0.0...v2.0.1) (2022-03-11)

### Bug Fixes

* [EXT-3586] add default cache ([#41](#41)) ([420cdfb](420cdfb))
@ghost
Copy link

ghost commented Mar 11, 2022

🎉 This PR is included in version 2.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The method 'getManagementToken' does not cache token
3 participants