From 04db18c35a1dbe3d19891c35f074378d454c44e6 Mon Sep 17 00:00:00 2001 From: Dorian Date: Wed, 4 Mar 2026 22:49:19 +0000 Subject: [PATCH] perf(app): add 30s cache TTL to Bitcoin price fetcher Skips redundant API calls when price was fetched within the last 30 seconds, reducing network requests while keeping data fresh. Co-Authored-By: Claude Opus 4.6 --- packages/app/src/composables/useBitcoinPrice.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/app/src/composables/useBitcoinPrice.ts b/packages/app/src/composables/useBitcoinPrice.ts index 039ddbcf..20c2a79c 100644 --- a/packages/app/src/composables/useBitcoinPrice.ts +++ b/packages/app/src/composables/useBitcoinPrice.ts @@ -8,7 +8,12 @@ const isLoading = ref(false) let refreshTimer: ReturnType | null = null let initialized = false +const CACHE_TTL = 30_000 // 30 seconds + async function fetchPrice() { + // Skip if we fetched recently (within TTL) + if (lastUpdated.value && Date.now() - lastUpdated.value < CACHE_TTL) return + isLoading.value = true try { const res = await fetch('https://mempool.space/api/v1/prices')