Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// @flow
import cache from 'memory-cache'
import fetch from 'isomorphic-fetch'
const TTL_MILISECONDS: number = 10 * 60 * 1000 // ten minutes
export default async function<T>(url: string, options?: Object): Promise<T> {
const cachedResponse = cache.get(url)
if (cachedResponse) return cachedResponse
// If there is no cached response,
// do the actual call and store the response
return fetch(url, options)
.then(response => response.json())
.then(response => {
cache.put(url, response, TTL_MILISECONDS)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment