Skip to content

Instantly share code, notes, and snippets.

@jkempff
Last active June 30, 2016 15:21
Show Gist options
  • Save jkempff/5fa84c79ca647ddb5853ba13fda312d3 to your computer and use it in GitHub Desktop.
Save jkempff/5fa84c79ca647ddb5853ba13fda312d3 to your computer and use it in GitHub Desktop.
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