Skip to main content

Overview

FastF1’s caching system significantly speeds up data loading and prevents exceeding API rate limits. The cache has two stages:
  1. Stage 1: Raw HTTP GET/POST request caching (using SQLite)
  2. Stage 2: Parsed data caching (using pickle files)
Caching is highly recommended for all FastF1 usage.

Cache Class

The Cache class provides class-level methods for configuring and managing the cache.

enable_cache()

Enables the API cache. This should be called at the beginning of your script, right after imports.

Parameters

str
required
Path to the directory for storing cached data. The directory must exist. Supports:
  • Environment variables: %LOCALAPPDATA%, $HOME, etc.
  • User home expansion: ~ or ~user
bool
default:"False"
Ignore if cached data was created with a different version of the API parser.
Not recommended - may cause crashes or errors due to incompatible data.
bool
default:"False"
Ignore existing cached data and re-download everything, updating the cache.
bool
default:"True"
Enable stage 1 caching (raw HTTP requests). Disable if you only want stage 2 caching.

Example

clear_cache()

Clears all cached data by deleting cache files.

Parameters

str | None
default:"None"
Path to the cache directory to clear. If None, uses the default cache directory.
bool
default:"False"
Also clear the stage 1 requests cache (SQLite database). If False, only clears stage 2 pickle files.

Example

Can be called without enabling the cache first.

get_cache_info()

Returns information about the cache directory and its size.

Returns

str | None
Path to the cache directory, or None if cache is not configured
int | None
Total size of the cache in bytes, or None if cache is not configured

Example

disabled()

Returns a context manager that temporarily disables the cache.

Returns

Context manager object
The context manager is not multithreading-safe.

set_disabled()

Disables the cache while keeping the configuration intact.
Disables both stage 1 and stage 2 caching. Use set_enabled() to re-enable.
Prefer using disabled() context manager for temporary disabling.
Not multithreading-safe.

set_enabled()

Re-enables the cache after it was disabled with set_disabled().
Cache must be properly configured first using enable_cache(). This method only re-enables a previously disabled cache.

offline_mode()

Enables or disables offline mode.

Parameters

bool
required
True to enable offline mode, False to disable
In offline mode:
  • No actual requests are sent to APIs
  • Only cached data is returned
  • Useful for working with unstable internet or freezing cache state
Must be called after enable_cache() when using a custom cache directory.

Example

ci_mode()

Enables or disables CI (Continuous Integration) mode.

Parameters

bool
required
True to enable CI mode, False to disable
In CI mode:
  • Cached requests are reused even if expired
  • Every request is only made once and cached indefinitely
  • Stage 2 (pickle) cache is disabled
  • Useful for test environments to reduce API calls and increase predictability
Must be called after enable_cache() when using a custom cache directory.

Cache Configuration

The cache directory is determined in order of precedence:
  1. Explicit call to enable_cache()
  2. FASTF1_CACHE environment variable
  3. OS-dependent default location

Default Cache Locations

Environment Variable

Set the FASTF1_CACHE environment variable to configure the default cache location:
This value is ignored if enable_cache() is called explicitly.

Cache Structure

The cache directory contains:

Manual Cache Management

You can manually delete specific events or sessions:
  1. Navigate to the cache directory
  2. Find the year/event/session folder
  3. Delete the folder
Deleting the SQLite file removes all HTTP request cache. You cannot selectively delete individual requests from it.

Helper Functions

While not part of the Cache class, these module-level functions work with the cache:

enable_cache()

Shorthand for Cache.enable_cache():
Available at module level for convenience.

Examples

Basic Setup

Force Refresh

Temporary Cache Disable

Check Cache Size

Working Offline

Best Practices

Caching dramatically improves performance and prevents hitting API rate limits. Always call enable_cache() at the start of your script.
Keep ignore_version=False (default) to avoid loading incompatible cached data after FastF1 updates.
The cache can grow large over time. Periodically check and clear it:
Add your cache directory to .gitignore:

Notes

Cached requests do not count towards API rate limits.
HTTP cache (stage 1) uses cache control headers and refreshes periodically (every 12 hours by default).
Deleting cache files reclaims disk space but means you’ll need to re-download data, which takes time and counts towards API rate limits.

See Also