Email or username:

Password:

Forgot your password?
Top-level
diabhoil

@mariusor No not really. But you could have a wrapper function like "cachedFetch(url) { if(!dictionary[url]) dictionary[url] = fetch(url); return dictionary[url] }"

dont know if the syntax is correct :D And its not tested...but something like that was in my mind ^^

3 comments
marius

@diabhoil yes, that's exactly what I started with, however the fetches happen all before the promises resolve, so the check fails for the URL. Maybe I just need to stick the promises in there.

diabhoil

@mariusor just tested with this const cachedFetch = (url) => { if(!dictionary[url]) { console.log("add to cache"); dictionary[url] = fetch(url); } else { console.log("just use from cache!"); } return dictionary[url]; } and it worked like expected when calling "await cachedFetch(url)"

marius

@diabhoil then maybe I get tripped by some awaits I have in the code. Thank you.

Go Up