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

cache #232

Open
dvlin-dev opened this issue Oct 7, 2023 · 1 comment · May be fixed by #235
Open

cache #232

dvlin-dev opened this issue Oct 7, 2023 · 1 comment · May be fixed by #235

Comments

@dvlin-dev
Copy link
Contributor

dvlin-dev commented Oct 7, 2023

Adding cache is necessary to avoid redundant processing of the same values through IntlMessageFormat, which significantly improves performance in scenarios with long lists.

@dvlin-dev
Copy link
Contributor Author

I added some code to see the performance improvement after caching, which is about 10 times faster.

test("cache", () => {
  const key = "HELLO";
  const variables = { name: 'World' };
  const currentLocale = "en-US"
  const cacheKey = key + JSON.stringify(variables) + currentLocale;

  intl.init({ locales, currentLocale });
  
  + console.time('Before caching')
  expect(intl.get(key, variables)).toBe("Hello, World");
  + console.timeEnd('Before caching')

  + console.time('After caching')
  expect(intl.get(key, variables)).toBe("Hello, World");
  + console.timeEnd('After caching')
});

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant