Skip to content

Added rates caching#4

Open
olarotseyi wants to merge 8 commits into
paul-shuvo:mainfrom
olarotseyi:main
Open

Added rates caching#4
olarotseyi wants to merge 8 commits into
paul-shuvo:mainfrom
olarotseyi:main

Conversation

@olarotseyi

Copy link
Copy Markdown

Similar update like the one I recently made to the nodejs-currency-converter

@olarotseyi

Copy link
Copy Markdown
Author

I just realized some issues with my rate caching solution.

  • In line 147, I should be returning a promise. You can update line 147 to this:
    return new Promise((resolve, _) => {
    resolve(this.ratesCache[currencyPair]);
    });
  • For the rates caching to work properly, you might have to export an instance of the CurrencyConverter class rather than the CurrencyConverter class itself. If the CurrencyConverter class is instantiated every time it is needed, the cache will be cleared and the caching will not be useful. Since the CurrencyConverter already supports chaining, you can export an instance of the CurrencyConverter (see below) therefore, the same CurrencyConverter instance is used everywhere in a project and the cache does not get cleared. This change might require some updates to the documentation in the README of the project.
    // exporting the currency converter instance will look like this:
    let currencyConverter = new CurrencyConverter();
    module.exports = currencyConverter;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant