Skip to content

Instantly share code, notes, and snippets.

@kellyrmilligan
Last active August 22, 2017 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellyrmilligan/6c69e7e3fa74b2cd65b43f511a12c0c4 to your computer and use it in GitHub Desktop.
Save kellyrmilligan/6c69e7e3fa74b2cd65b43f511a12c0c4 to your computer and use it in GitHub Desktop.
multiple calls with client side caching
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