Last active
August 22, 2017 18:35
-
-
Save kellyrmilligan/6c69e7e3fa74b2cd65b43f511a12c0c4 to your computer and use it in GitHub Desktop.
multiple calls with client side caching
This file contains 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
import CacheClientPromise from 'cache-client-promise' | |
const myCache = new CacheClientPromise(); | |
[{ | |
id: 1234, | |
title: 'test', | |
view: 'two-column' | |
}, | |
{ | |
id: 1234, | |
title: 'test', | |
view: 'image-only' | |
}] | |
.forEach((article) => { | |
myCache.get(`article-${article.id}`, function () { | |
return fetch(`/api/articles/${article.id}`, { | |
method: 'GET', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
credentials: 'same-origin' | |
}) | |
.then(response => response.json()) | |
}) | |
.then((articleDeets) => { | |
article.details = articleDeets | |
}) | |
.catch((reason) => { | |
//something happened most likely in your requesting function | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment