mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
14 lines
306 B
JavaScript
14 lines
306 B
JavaScript
![]() |
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;
|
||
|
}
|
||
|
}
|