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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9032e8cd60
commit
04db18c35a
@@ -8,7 +8,12 @@ const isLoading = ref(false)
|
||||
let refreshTimer: ReturnType<typeof setInterval> | 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')
|
||||
|
||||
Reference in New Issue
Block a user