From 2271cc00440d4446fb018762cecd47b69e8fffd2 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Fri, 30 Sep 2022 21:56:22 +0300 Subject: [PATCH] cache github response for 5 min --- src/components/version.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/version.jsx b/src/components/version.jsx index 72449a7a0..522112191 100644 --- a/src/components/version.jsx +++ b/src/components/version.jsx @@ -3,6 +3,8 @@ import useSWR from "swr"; import { compareVersions } from "compare-versions"; import { MdNewReleases } from "react-icons/md"; +import cachedFetch from "utils/proxy/cached-fetch"; + export default function Version() { const { t, i18n } = useTranslation(); @@ -10,7 +12,9 @@ export default function Version() { const revision = process.env.NEXT_PUBLIC_REVISION ?? "dev"; const version = process.env.NEXT_PUBLIC_VERSION ?? "dev"; - const { data: releaseData } = useSWR("https://api.github.com/repos/benphelps/homepage/releases"); + const cachedFetcher = (resource) => cachedFetch(resource, 5).then((res) => res.json()); + + const { data: releaseData } = useSWR("https://api.github.com/repos/benphelps/homepage/releases", cachedFetcher); // use Intl.DateTimeFormat to format the date const formatDate = (date) => {