orchestrator
¶
Cache Orchestrator - Coordinates all specialized cache services.
This module provides a unified interface for interacting with multiple specialized cache services while maintaining the existing API contract.
Key Features: - Coordinates AlbumCacheService, ApiCacheService, and GenericCacheService - Maintains backward compatibility with existing CacheService API - Intelligent routing based on operation type and content - Centralized configuration management and metrics
CacheOrchestrator
¶
Bases: CacheServiceProtocol
Orchestrates multiple specialized cache services with unified interface.
Initialize CacheOrchestrator with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AppConfig
|
Typed application configuration |
required |
logger
|
Logger | None
|
Optional logger instance |
None
|
Source code in src/services/cache/orchestrator.py
initialize
async
¶
Initialize all cache services.
Source code in src/services/cache/orchestrator.py
get_album_year
async
¶
Get album release year from cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Album release year if found, None otherwise |
Source code in src/services/cache/orchestrator.py
store_album_year
async
¶
Store album release year in cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artist
|
str
|
Artist name |
required |
album
|
str
|
Album name |
required |
year
|
str
|
Album release year |
required |
confidence
|
int
|
Confidence score 0-100 (higher = more trustworthy) |
0
|
Source code in src/services/cache/orchestrator.py
get_async
async
¶
Asynchronous get with optional compute function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data
|
CacheableKey
|
Cache key or "ALL" for all entries |
required |
compute_func
|
Callable[[], Future[CacheableValue]] | None
|
Optional compute function to calculate value if not cached |
None
|
Returns:
| Type | Description |
|---|---|
list[TrackDict] | CacheableValue
|
Cached or computed value |
Source code in src/services/cache/orchestrator.py
set
¶
Set value in generic cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data
|
CacheableKey
|
Cache key |
required |
value
|
CacheableValue
|
Value to cache |
required |
ttl
|
int | None
|
Optional TTL in seconds |
None
|
Source code in src/services/cache/orchestrator.py
set_async
async
¶
Async alias for set method (backward compatibility).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data
|
CacheableKey
|
Cache key |
required |
value
|
CacheableValue
|
Value to cache |
required |
ttl
|
int | None
|
Optional TTL in seconds |
None
|
Source code in src/services/cache/orchestrator.py
get
¶
Get value from generic cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data
|
CacheableKey
|
Cache key |
required |
Returns:
| Type | Description |
|---|---|
CacheableValue | None
|
Cached value if found, None otherwise |
Source code in src/services/cache/orchestrator.py
invalidate_for_track
async
¶
Invalidate all cache entries related to a track.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
TrackDict
|
Track dictionary with artist and album information |
required |
Source code in src/services/cache/orchestrator.py
save_all_to_disk
async
¶
Save all persistent caches to disk.
Source code in src/services/cache/orchestrator.py
invalidate
¶
Invalidate specific cache entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data
|
CacheableKey
|
Cache key to invalidate |
required |
invalidate_all
async
¶
Clear all cache entries across all services.
Source code in src/services/cache/orchestrator.py
load_cache
async
¶
save_cache
async
¶
get_last_run_timestamp
async
¶
Get the timestamp of the last cache run.
Returns:
| Type | Description |
|---|---|
datetime
|
Last run timestamp, or epoch (1970-01-01) if never run |
Source code in src/services/cache/orchestrator.py
get_album_year_from_cache
async
¶
get_album_year_entry_from_cache
async
¶
Get full album cache entry for an artist/album pair.
store_album_year_in_cache
async
¶
Store album year in persistent cache.
invalidate_album_cache
async
¶
invalidate_all_albums
async
¶
sync_cache
async
¶
get_cached_api_result
async
¶
Get cached API result for an artist/album from a specific source.
Source code in src/services/cache/orchestrator.py
set_cached_api_result
async
¶
Cache an API result for an artist/album from a specific source.
Source code in src/services/cache/orchestrator.py
generate_album_key
staticmethod
¶
Generate a unique key for an artist/album pair.
Source code in src/services/cache/orchestrator.py
clear
async
¶
Clear all entries from all caches (generic, album, and API caches).
shutdown
async
¶
Gracefully shutdown background tasks for cache services.
Shuts down: 1. ApiCacheService background tasks (cache invalidation, etc.) 2. GenericCacheService cleanup task