homepage/src/utils/cached-fetch.js

14 lines
306 B
JavaScript
Raw Normal View History

2022-08-24 10:44:35 +03:00
import cache from "memory-cache";
export default async function cachedFetch(url, duration) {
const cached = cache.get(url);
if (cached) {
return cached;
} else {
const data = await fetch(url).then((res) => res.json());
cache.put(url, data, duration * 1000 * 60);
return data;
}
}