Expand description
Cache management command implementation with comprehensive cleanup capabilities.
This module provides sophisticated cache management functionality through
the cache
subcommand, enabling users to inspect, maintain, and clean up
various types of cached data that SubX accumulates during operation. The
cache system is crucial for performance optimization and API cost reduction.
§Cache System Overview
SubX maintains multiple types of caches to optimize performance:
§AI Analysis Cache
- Purpose: Store results from expensive AI API calls
- Content: File analysis results, matching decisions, confidence scores
- Benefits: Reduce API costs, improve response times, enable offline review
- Location:
~/.config/subx/ai_cache/
- Format: JSON files with content hashes as keys
§Dry-run Results Cache
- Purpose: Preserve preview results for later application
- Content: Planned file operations, rename proposals, backup locations
- Benefits: Review before apply, batch operations, undo planning
- Location:
~/.config/subx/match_cache.json
- Format: Structured JSON with operation metadata
§Audio Analysis Cache
- Purpose: Store computationally expensive audio processing results
- Content: Speech detection patterns, timing analysis, correlation data
- Benefits: Faster re-synchronization, batch processing optimization
- Location:
~/.config/subx/audio_cache/
- Format: Binary files with audio fingerprints
§Configuration Cache
- Purpose: Processed and validated configuration data
- Content: Merged configuration, validation results, computed settings
- Benefits: Faster application startup, consistency validation
- Location:
~/.config/subx/config_cache/
- Format: Serialized configuration structures
§Cache Management Operations
§Clear Operation
- Scope: Remove all cached data across all cache types
- Safety: Non-destructive to actual subtitle and video files
- Impact: Next operations will require fresh computation/API calls
- Recovery: All cached data can be regenerated through normal usage
§Status Operation (Future Enhancement)
- Information: Cache size, age, hit rates, storage usage
- Analysis: Identify stale or corrupted cache entries
- Optimization: Suggest cache maintenance actions
- Reporting: Usage statistics and efficiency metrics
§Selective Clear (Future Enhancement)
- Type-specific: Clear only AI, audio, or configuration cache
- Age-based: Remove cache entries older than specified time
- Size-based: Remove least recently used entries to reduce disk usage
- Pattern-based: Clear cache entries matching specific criteria
§Performance Impact
§After Cache Clear
- AI Operations: Will require fresh API calls (increased time/cost)
- Audio Processing: Re-analysis required for sync operations
- Configuration: Slight startup delay for configuration processing
- File Operations: No impact on actual file processing capabilities
§Cache Regeneration
- Automatic: Caches rebuild naturally during normal operations
- Intelligent: Only necessary computations are performed
- Progressive: Cache rebuilds incrementally as features are used
- Optimized: New cache generation benefits from previous optimizations
§Examples
ⓘ
use subx_cli::cli::{CacheArgs, CacheAction};
use subx_cli::commands::cache_command;
// Clear all cache data
let clear_args = CacheArgs {
action: CacheAction::Clear,
};
cache_command::execute(clear_args).await?;
Functions§
- execute
- Execute cache management operations with comprehensive cleanup and validation.
- execute_
with_ config - Execute cache management command with injected configuration service.