ferrite-cache
High-performance asynchronous image caching system for the Ferrite image viewer.
Features
- Asynchronous image loading and decoding using Tokio
- LRU (Least Recently Used) cache eviction strategy
- Efficient memory management with Arc-based sharing
- Image format support via the
imagecrate - Comprehensive error handling and logging
- Optional performance metrics via
ferrite-metricsfeature
Usage
Add to your Cargo.toml:
[]
= "0.1"
Basic Usage
use ;
use tokio;
use Arc;
async
Command Line Tools
The crate includes two binary tools for testing and benchmarking:
read_image
Loads and caches a single image, with detailed timing information:
read_directory
Processes and caches all images in a directory with parallel loading:
Performance Tips
- Cache Size: Set
max_image_countbased on available memory and typical image sizes - Worker Threads: Adjust runtime worker threads based on CPU cores
- Preloading: Use read_directory for batch preloading of frequently accessed images
Error Handling
The crate provides detailed error types:
CacheError::ImageLoad- File reading or format errorsCacheError::CapacityExceeded- Cache size limitsCacheError::FileSystem- OS-level file operationsCacheError::Config- Configuration issues
Contributing
Contributions welcome! Please check out our Contributing Guide.
License
MIT License