You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
14 lines
306 B
14 lines
306 B
2 years ago
|
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;
|
||
|
}
|
||
|
}
|