tif1 provides a programmatic interface to manage its two-tier caching system (Memory + SQLite).
get_cache
Cache Management
clear()
Removes all entries from both the in-memory LRU cache and the persistent SQLite database.
has_session_data(year, gp, session)
Checks if the cache contains any data for a specific session without loading it. Returns True if any JSON or telemetry data exists for the session.
Parameters:
year(int): Season yeargp(str): Grand Prix identifier (e.g.,"Belgian_Grand_Prix")session(str): Session type (e.g.,"Race","Qualifying")
bool
close()
Closes the SQLite database connection. This is called automatically on exit, but can be used manually if needed.
General Cache Access
get(key)
Returns the cached JSON-serializable data for a specific key. Returns None if not found.
Parameters:
key(str): Cache key in format"{year}/{gp}/{session}/{file}.json"
Any | None
set(key, data)
Stores data in the cache with the specified key. Updates both memory and SQLite caches.
Parameters:
key(str): Cache keydata(Any): JSON-serializable data to cache
Telemetry Cache Access
Telemetry data uses a dedicated SQLite table optimized for lap-by-lap queries.get_telemetry(year, gp, session, driver, lap)
Retrieves telemetry data for a specific lap. Returns None if not found.
Parameters:
year(int): Season yeargp(str): Grand Prix identifiersession(str): Session typedriver(str): Driver code (e.g.,"VER","HAM")lap(int): Lap number
Any | None
set_telemetry(year, gp, session, driver, lap, data)
Stores telemetry data for a specific lap.
Parameters:
year(int): Season yeargp(str): Grand Prix identifiersession(str): Session typedriver(str): Driver codelap(int): Lap numberdata(Any): Telemetry data to cache
get_telemetry_batch(year, gp, session, driver_laps)
Retrieves multiple telemetry entries in a single optimized batch query. More efficient than multiple individual get_telemetry() calls.
Parameters:
year(int): Season yeargp(str): Grand Prix identifiersession(str): Session typedriver_laps(list[tuple[str, int]]): List of (driver_code, lap_number) tuples
dict[tuple[str, int], Any] - Dictionary mapping (driver, lap) to telemetry data
Async Methods
All cache read/write operations have async variants for use in async contexts:get_async(key)- Async version ofget()set_async(key, data)- Async version ofset()get_telemetry_async(year, gp, session, driver, lap)- Async version ofget_telemetry()set_telemetry_async(year, gp, session, driver, lap, data)- Async version ofset_telemetry()get_telemetry_batch_async(year, gp, session, driver_laps)- Async version ofget_telemetry_batch()
Cache Attributes
| Attribute | Type | Description |
|---|---|---|
cache_dir | Path | The directory where the cache.sqlite file is stored. |
db_path | Path | Full path to the cache.sqlite database file. |
read_only | bool | If True, the cache will not save any new data to disk. |