Last active
June 30, 2016 15:21
-
-
Save jkempff/5fa84c79ca647ddb5853ba13fda312d3 to your computer and use it in GitHub Desktop.
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
var fetchWithCache = (function () { | |
var cache = {}; | |
const doFetch = (url, options) => { | |
return cache[url] ? cache[url] : cache[url] = fetch(url, options) | |
.then(response => response.json()); | |
}; | |
doFetch.flush = () => (cache = {}, true); | |
return doFetch; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment