mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00

- Needed to decompose i18n labels for Unifi widget in order for field visibility setting to work correctly - Fixed weird edge case where a call to cached-fetch would fail if no duration was passed - Have VS Code hide the .next and node_modules folders from tree view
19 lines
409 B
JavaScript
19 lines
409 B
JavaScript
import cache from "memory-cache";
|
|
|
|
const defaultDuration = 5;
|
|
|
|
export default async function cachedFetch(url, duration) {
|
|
const cached = cache.get(url);
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
duration = duration || defaultDuration;
|
|
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
|
|
const data = await fetch(url).then((res) => res.json());
|
|
cache.put(url, data, duration * 1000 * 60);
|
|
return data;
|
|
}
|