cache_config
¶
Smart Cache Configuration with Event-Driven Invalidation.
This module provides intelligent cache configuration that understands the lifecycle of media library tracks and optimizes caching strategies accordingly.
Key Features: - Event-driven invalidation for media library tracks - Content-type aware TTL management - Integration with fingerprint-based change detection - Lifecycle management for persistent vs temporary cache entries
CacheContentType
¶
Bases: Enum
Types of cached content with different lifecycle requirements.
InvalidationStrategy
¶
Bases: Enum
Cache invalidation strategies.
CachePolicy
dataclass
¶
CachePolicy(
content_type,
ttl_seconds,
invalidation_strategy,
max_size_mb=None,
cleanup_threshold=0.8,
description="",
)
Configuration for a specific type of cached content.
SmartCacheConfig
¶
Smart cache configuration with content-aware policies.
Initialize smart cache configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AppConfig | None
|
Optional typed application configuration |
None
|
Source code in src/services/cache/cache_config.py
get_policy
¶
Get cache policy for specific content type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_type
|
CacheContentType
|
Type of cached content |
required |
Returns:
| Type | Description |
|---|---|
CachePolicy
|
Cache policy with TTL and invalidation strategy |
Source code in src/services/cache/cache_config.py
get_ttl
¶
Get TTL in seconds for specific content type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_type
|
CacheContentType
|
Type of cached content |
required |
Returns:
| Type | Description |
|---|---|
int
|
TTL in seconds |
Source code in src/services/cache/cache_config.py
should_use_fingerprint_validation
¶
Check if content type should use fingerprint-based validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_type
|
CacheContentType
|
Type of cached content |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if fingerprint validation should be used |
Source code in src/services/cache/cache_config.py
should_use_event_invalidation
¶
Check if content type should use event-driven invalidation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_type
|
CacheContentType
|
Type of cached content |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if event-driven invalidation should be used |
Source code in src/services/cache/cache_config.py
is_persistent_cache
staticmethod
¶
Check if content type represents persistent cache data.
Persistent cache should survive application restarts and only be invalidated by specific events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_type
|
CacheContentType
|
Type of cached content |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if cache should be persistent |
Source code in src/services/cache/cache_config.py
CacheEventType
¶
Bases: Enum
Types of cache invalidation events.
CacheEvent
dataclass
¶
Cache event for event-driven invalidation.
__post_init__
¶
Validate event data.
Source code in src/services/cache/cache_config.py
EventDrivenCacheManager
¶
Manages event-driven cache invalidation.
Initialize event-driven cache manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SmartCacheConfig
|
Smart cache configuration instance |
required |
Source code in src/services/cache/cache_config.py
register_event_handler
¶
Register event handler for specific event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
CacheEventType
|
Type of cache event |
required |
handler
|
Callable[[CacheEvent], None]
|
Callable to handle the event |
required |
Source code in src/services/cache/cache_config.py
emit_event
¶
Emit cache event to trigger invalidation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
CacheEvent
|
Cache event to emit |
required |
Source code in src/services/cache/cache_config.py
should_invalidate_for_event
¶
Check if cache should be invalidated for given event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_type
|
CacheContentType
|
Type of cached content |
required |
event
|
CacheEvent
|
Cache event that occurred |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if cache should be invalidated |