cache_manager
¶
Track cache management module.
This module handles track caching operations including: - Memory cache retrieval and validation - Library snapshot persistence - Delta track merging
TrackCacheManager
¶
Manages track caching and snapshot operations.
This class handles: - Retrieving and validating cached tracks - Loading and saving library snapshots - Merging delta updates into snapshots
Initialize the cache manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_service
|
CacheServiceProtocol
|
Service for memory/disk cache operations |
required |
snapshot_service
|
LibrarySnapshotServiceProtocol | None
|
Service for library snapshot operations (optional) |
required |
console_logger
|
Logger
|
Logger for info/debug messages |
required |
current_time_func
|
Callable[[], datetime] | None
|
Optional function to get current time (for testing) |
None
|
Source code in src/core/tracks/cache_manager.py
get_cached_tracks
async
¶
Retrieve tracks from the cache with type validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_key
|
str
|
Cache key to retrieve |
required |
Returns:
| Type | Description |
|---|---|
Sequence[TrackDict] | None
|
List of tracks if found and valid, None otherwise |
Source code in src/core/tracks/cache_manager.py
load_snapshot
async
¶
Load tracks from library snapshot if available and valid.
Returns:
| Type | Description |
|---|---|
list[TrackDict] | None
|
List of tracks if snapshot is valid, None otherwise |
Source code in src/core/tracks/cache_manager.py
merge_tracks
staticmethod
¶
Merge delta updates into the existing snapshot while preserving order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
existing
|
list[TrackDict]
|
Existing snapshot tracks |
required |
updates
|
list[TrackDict]
|
New/updated tracks from delta fetch |
required |
Returns:
| Type | Description |
|---|---|
list[TrackDict]
|
Merged list of tracks |
Source code in src/core/tracks/cache_manager.py
update_snapshot
async
¶
Persist the latest snapshot, metadata, and delta state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[TrackDict]
|
Full list of tracks to save |
required |
processed_track_ids
|
Sequence[str] | None
|
Optional list of track IDs that were processed in this delta |
None
|
library_mtime_override
|
datetime | None
|
If provided, use this as the library modification time instead of the current mtime. This should be captured BEFORE fetching tracks to prevent race conditions where new tracks are added during the fetch. |
None
|