Open dvlin-dev opened 10 months ago
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')
});
Adding cache is necessary to avoid redundant processing of the same values through IntlMessageFormat, which significantly improves performance in scenarios with long lists.