rattler_build_source_cache
A unified source cache for Rattler-Build that handles Git repositories, URL downloads, and local paths with proper caching, extraction, and concurrent access control.
Features
- Unified Cache: Single interface for Git, URL, and Path sources
- Content-Addressable Storage: Sources are indexed by content hash for deduplication
- Concurrent Access Control: File locking ensures safe concurrent access from multiple processes
- Automatic Extraction: Archives (.tar.gz, .zip, .7z, etc.) are automatically extracted
- Cache Management: Automatic cleanup of old entries, configurable TTL
- Progress Tracking: Optional progress callbacks for downloads and extractions
- Checksum Validation: SHA256 and MD5 checksum support for URL downloads
Usage
use ;
async
Cache Structure
The cache directory is organized as follows:
cache_dir/
├── .metadata/ # JSON metadata files for each cache entry
│ ├── <hash>.json
│ └── ...
├── .locks/ # Lock files for concurrent access control
│ ├── <hash>.lock
│ └── ...
├── <hash>_file.tar.gz # Downloaded archives
├── <hash>_extracted/ # Extracted archive contents
└── git_<hash>/ # Cloned git repositories
Configuration
The SourceCacheBuilder provides various configuration options:
cache_dir: Location of the cache directory (defaults to system cache dir)client: Custom HTTP client for downloadsmax_age: Maximum age before entries are considered staleenable_cleanup: Enable automatic cleanup of old entriescleanup_interval: How often to run cleanupenable_compression: Whether to compress cached files (future feature)max_concurrent_downloads: Limit concurrent downloadsprogress_handler: Custom progress reporting
Thread Safety
The cache is designed for safe concurrent access:
- File locks prevent multiple processes from modifying the same cache entry
- The index uses async RwLock for thread-safe in-memory access
- Lock files are automatically cleaned up when guards are dropped
License
BSD-3-Clause