Cache Manager Module (00e-cache-mgr.sh)¶
Version: v3.5.0
File:src/lib/00e-cache-mgr.sh
Dependencies:helpers.sh
Overview¶
Centralized download caching with deduplication, integrity checks, and cleanup. Prevents re-downloading of already-fetched packages across runs.
Functions¶
Cache Initialization¶
_cache_init()¶
Initializes cache directory and index file.
Cache Key Generation¶
_cache_key(url)¶
Generates cache key from URL using SHA256.
Cache Operations¶
_cache_hit(url)¶
Checks if URL is cached.
_cache_get(url)¶
Gets cached file path.
_cache_store(url, file)¶
Stores file in cache.
_cache_download(url, output)¶
Downloads with caching. Returns cached file if available.
Cache Maintenance¶
_cache_cleanup()¶
Cleans old cache entries based on age and size.
_cache_cleanup
# Removes entries older than CACHE_MAX_AGE_DAYS
# Removes entries if cache exceeds CACHE_MAX_SIZE_MB
_cache_stats()¶
Shows cache statistics.
Variables¶
| Variable | Description | Default |
|---|---|---|
CACHE_MAX_AGE_DAYS | Maximum cache age | 30 |
CACHE_MAX_SIZE_MB | Maximum cache size | 5120 (5GB) |
_CACHE_ROOT | Cache directory | ~/.cache/opencode-setup/packages |
_CACHE_INDEX | Cache index file | ~/.cache/opencode-setup/packages/.cache-index.json |
Usage¶
# Source the module
source src/lib/helpers.sh
source src/lib/00e-cache-mgr.sh
# Show help
_cache_help
# Initialize cache
_cache_init
# Download with caching
path=$(_cache_download "https://example.com/file.tar.gz")
# Check cache statistics
_cache_stats
# Clean old entries
_cache_cleanup
Cache Structure¶
~/.cache/opencode-setup/packages/
├── .cache-index.json # Cache index
├── .cache-log # Cache hit/miss log
├── a1b2c3d4e5f6g7h8 # Cached file (hash key)
├── i9j0k1l2m3n4o5p6 # Cached file (hash key)
└── ...
Integrity Checks¶
- SHA256 hash verification
- File size validation
- Timestamp tracking
See Also¶
- core.md - Core infrastructure
- parallel.md - Parallel execution
- helpers.sh - Helper functions