Skip to content

Instantly share code, notes, and snippets.

@SBoudrias
Created April 3, 2020 04:24
Show Gist options
  • Save SBoudrias/6ab4504432a5da827c7c3eb397308b6b to your computer and use it in GitHub Desktop.
Save SBoudrias/6ab4504432a5da827c7c3eb397308b6b to your computer and use it in GitHub Desktop.
Using a weakmap as cache.
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