DataFetcher
Defined in: packages/core/src/data/data-fetcher.ts:146
HTTP data fetcher with caching and retry support.
Remarks
Section titled “Remarks”Features:
- In-memory caching with TTL
- Conditional requests (If-None-Match, If-Modified-Since)
- Automatic retry with exponential backoff
- Request timeout and cancellation
- GeoJSON validation
- Lifecycle callbacks
Example
Section titled “Example”const fetcher = new DataFetcher({ cache: { enabled: true, defaultTTL: 300000, maxSize: 100 }, retry: { enabled: true, maxRetries: 3, initialDelay: 1000, maxDelay: 10000 }, timeout: 30000,});
// Fetch with cachingconst result = await fetcher.fetch('https://example.com/data.geojson');console.log(`Fetched ${result.featureCount} features in ${result.duration}ms`);
// Prefetch for later useawait fetcher.prefetch('https://example.com/data2.geojson');
// Force fresh fetchconst fresh = await fetcher.fetch(url, { skipCache: true });Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DataFetcher(
config?):DataFetcher
Defined in: packages/core/src/data/data-fetcher.ts:175
Create a new DataFetcher instance
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config? | Partial<FetcherConfig> | Fetcher configuration |
Returns
Section titled “Returns”DataFetcher
Methods
Section titled “Methods”abortAll()
Section titled “abortAll()”abortAll():
void
Defined in: packages/core/src/data/data-fetcher.ts:316
Abort all active requests
Returns
Section titled “Returns”void
clearCache()
Section titled “clearCache()”clearCache():
void
Defined in: packages/core/src/data/data-fetcher.ts:300
Clear all cached entries
Returns
Section titled “Returns”void
fetch()
Section titled “fetch()”fetch(
url,options?):Promise<FetchResult>
Defined in: packages/core/src/data/data-fetcher.ts:212
Fetch GeoJSON data from a URL
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
url | string | URL to fetch from |
options | FetchOptions | Fetch options |
Returns
Section titled “Returns”Promise<FetchResult>
Fetch result with data and metadata
Throws
Section titled “Throws”On network error, timeout, invalid JSON, or non-GeoJSON response
Example
Section titled “Example”const result = await fetcher.fetch( 'https://example.com/data.geojson', { ttl: 60000, // 1 minute cache onRetry: (attempt, delay, error) => { console.log(`Retry ${attempt} in ${delay}ms: ${error.message}`); }, });getCacheStats()
Section titled “getCacheStats()”getCacheStats():
CacheStats
Defined in: packages/core/src/data/data-fetcher.ts:309
Get cache statistics
Returns
Section titled “Returns”Cache stats including size, hits, misses, and hit rate
invalidate()
Section titled “invalidate()”invalidate(
url):void
Defined in: packages/core/src/data/data-fetcher.ts:293
Invalidate cached entry for a URL
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
url | string | URL to invalidate |
Returns
Section titled “Returns”void
Example
Section titled “Example”// Force next fetch to get fresh datafetcher.invalidate('https://example.com/data.geojson');prefetch()
Section titled “prefetch()”prefetch(
url,ttl?):Promise<void>
Defined in: packages/core/src/data/data-fetcher.ts:278
Prefetch data and store in cache
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
url | string | URL to prefetch |
ttl? | number | Optional custom TTL for cached entry |
Returns
Section titled “Returns”Promise<void>
Remarks
Section titled “Remarks”Useful for preloading data that will be needed soon. Does not return the data.
Example
Section titled “Example”// Prefetch data for quick access laterawait fetcher.prefetch('https://example.com/data.geojson', 600000);