Skip to content

Instantly share code, notes, and snippets.

@omidnikrah
Last active July 13, 2020 06:48
Show Gist options
  • Save omidnikrah/bde4991832769cb3517ae11137060d6f to your computer and use it in GitHub Desktop.
Save omidnikrah/bde4991832769cb3517ae11137060d6f to your computer and use it in GitHub Desktop.
Simple Cashe API Requests
class CacheRequests {
constructor() {
this.caches = new Map();
}
set(url, response) {
this.caches.set(url, response);
}
get(url) {
return this.caches.get(url);
}
has(url) {
return this.caches.has(url);
}
}
const cache = new CacheRequests();
const Request = (url, options) => {
if (cache.has(url)) {
return cache.get(url);
}
fetch(url, options).then((response) => {
console.log(response);
cache.set(url, response);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment