From 2ec2cda475e6a97f3f54b7e49ea214ffa77f591d Mon Sep 17 00:00:00 2001 From: Roland <33993199+rolznz@users.noreply.github.com> Date: Wed, 31 Jul 2024 22:24:26 +0700 Subject: [PATCH] Fix: cache alby user calls (#377) * fix: cache fetches to alby user endpoint for 5 minutes by default * fix: also cache alby balance calls --- frontend/src/hooks/useAlbyBalance.ts | 6 ++++-- frontend/src/hooks/useAlbyMe.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/hooks/useAlbyBalance.ts b/frontend/src/hooks/useAlbyBalance.ts index 2b3b7267..67ac7dd8 100644 --- a/frontend/src/hooks/useAlbyBalance.ts +++ b/frontend/src/hooks/useAlbyBalance.ts @@ -1,8 +1,10 @@ import useSWR from "swr"; -import { swrFetcher } from "src/utils/swr"; import { AlbyBalance } from "src/types"; +import { swrFetcher } from "src/utils/swr"; export function useAlbyBalance() { - return useSWR("/api/alby/balance", swrFetcher); + return useSWR("/api/alby/balance", swrFetcher, { + dedupingInterval: 5 * 60 * 1000, // 5 minutes + }); } diff --git a/frontend/src/hooks/useAlbyMe.ts b/frontend/src/hooks/useAlbyMe.ts index 0fa3f1a4..688fa92f 100644 --- a/frontend/src/hooks/useAlbyMe.ts +++ b/frontend/src/hooks/useAlbyMe.ts @@ -4,5 +4,7 @@ import { AlbyMe } from "src/types"; import { swrFetcher } from "src/utils/swr"; export function useAlbyMe() { - return useSWR("/api/alby/me", swrFetcher); + return useSWR("/api/alby/me", swrFetcher, { + dedupingInterval: 5 * 60 * 1000, // 5 minutes + }); }