Created
April 3, 2020 04:24
-
-
Save SBoudrias/5441ea54a08f9c8d037d394d219bbbe0 to your computer and use it in GitHub Desktop.
Using a weakmap as cache.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cache = new WeakMap(); | |
export async function getUserForReq(req) { | |
if (cache.has(req)) { | |
return cache.get(req); | |
} | |
return await User.get(req.form.session_id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment