Upgrades to Live and API Caching

This commit is contained in:
2026-03-27 00:30:53 -04:00
parent 7c2fcfef8d
commit 360bde4602
19 changed files with 838 additions and 225 deletions

View File

@@ -7,15 +7,27 @@ import (
type OpenF1Client struct {
url string
apiKey string
httpClient *http.Client
cache *FileCache
cache *Cache
}
func NewOpenF1Client(url string, timeout time.Duration) *OpenF1Client {
return &OpenF1Client{
url: url,
httpClient: &http.Client{Timeout: timeout},
cache: NewFileCache(),
cache: NewCache(),
}
}
// NewOpenF1ClientWithKey creates a client that authenticates with a Bearer token.
// This allows access during live sessions (paid tier).
func NewOpenF1ClientWithKey(url string, timeout time.Duration, apiKey string) *OpenF1Client {
return &OpenF1Client{
url: url,
apiKey: apiKey,
httpClient: &http.Client{Timeout: timeout},
cache: NewCache(),
}
}
@@ -28,3 +40,8 @@ func (c *OpenF1Client) CacheStats() CacheStats {
func (c *OpenF1Client) CacheSize() (int, int64) {
return c.cache.Size()
}
// Close releases resources held by the client (closes the cache database).
func (c *OpenF1Client) Close() error {
return c.cache.Close()
}