Skip to content

Commit 6b6f45a

Browse files
authored
Single cache map (#49)
1 parent 487d729 commit 6b6f45a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

index.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ function normalise(input) {
8585
return input.replace(/_/, '-');
8686
}
8787

88-
// Uses a map as a simple memoization technique without having to import `mem`
89-
const asyncCache = new Map();
88+
const cache = new Map();
9089

9190
module.exports = async (options = defaultOptions) => {
92-
if (asyncCache.has(options.spawn)) {
93-
return asyncCache.get(options.spawn);
91+
if (cache.has(options.spawn)) {
92+
return cache.get(options.spawn);
9493
}
9594

9695
let locale;
@@ -110,15 +109,13 @@ module.exports = async (options = defaultOptions) => {
110109
} catch {}
111110

112111
const normalised = normalise(locale || defaultLocale);
113-
asyncCache.set(options.spawn, normalised);
112+
cache.set(options.spawn, normalised);
114113
return normalised;
115114
};
116115

117-
const syncCache = new Map();
118-
119116
module.exports.sync = (options = defaultOptions) => {
120-
if (syncCache.has(options.spawn)) {
121-
return syncCache.get(options.spawn);
117+
if (cache.has(options.spawn)) {
118+
return cache.get(options.spawn);
122119
}
123120

124121
let locale;
@@ -137,6 +134,6 @@ module.exports.sync = (options = defaultOptions) => {
137134
} catch {}
138135

139136
const normalised = normalise(locale || defaultLocale);
140-
syncCache.set(options.spawn, normalised);
137+
cache.set(options.spawn, normalised);
141138
return normalised;
142139
};

0 commit comments

Comments
 (0)