Files
frontend-svelte/src/shared/api/queryClient.ts
T

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-01-13 19:49:51 +03:00
import { QueryClient } from '@tanstack/query-core';
/**
* TanStack Query client instance
*
* Configured for optimal caching and refetching behavior.
* Used by all font stores for data fetching and caching.
*
* Cache behavior:
* - Data stays fresh for 5 minutes (staleTime)
* - Unused data is garbage collected after 10 minutes (gcTime)
* - No refetch on window focus (reduces unnecessary network requests)
* - 3 retries with exponential backoff on failure
2026-01-13 19:49:51 +03:00
*/
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
2026-04-17 12:14:55 +03:00
/**
* Data remains fresh for 5 minutes after fetch
*/
2026-01-13 19:49:51 +03:00
staleTime: 5 * 60 * 1000,
2026-04-17 12:14:55 +03:00
/**
* Unused cache entries are removed after 10 minutes
*/
2026-01-13 19:49:51 +03:00
gcTime: 10 * 60 * 1000,
2026-04-17 12:14:55 +03:00
/**
* Don't refetch when window regains focus
*/
2026-01-13 19:49:51 +03:00
refetchOnWindowFocus: false,
2026-04-17 12:14:55 +03:00
/**
* Refetch on mount if data is stale
*/
2026-01-13 19:49:51 +03:00
refetchOnMount: true,
2026-04-17 12:14:55 +03:00
/**
* Retry failed requests up to 3 times
*/
2026-01-13 19:49:51 +03:00
retry: 3,
/**
* Exponential backoff for retries
* 1s, 2s, 4s, 8s... capped at 30s
2026-01-13 19:49:51 +03:00
*/
retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, 30000),
},
},
});