| Crates.io | ferrite-cache |
| lib.rs | ferrite-cache |
| version | 0.1.25 |
| created_at | 2024-12-24 14:13:57.484379+00 |
| updated_at | 2025-07-21 14:51:07.900909+00 |
| description | Caching functionality for Ferrite image viewer |
| homepage | |
| repository | https://github.com/master-of-zen/ferrite |
| max_upload_size | |
| id | 1493917 |
| size | 74,570 |
High-performance asynchronous image caching system for the Ferrite image viewer.
image crateferrite-metrics featureAdd to your Cargo.toml:
[dependencies]
ferrite-cache = "0.1"
use ferrite_cache::{CacheManager, CacheConfig};
use tokio;
use std::sync::Arc;
#[tokio::main]
async fn main() {
// Initialize runtime
let runtime = Arc::new(
tokio::runtime::Builder::new_multi_thread()
.worker_threads(4)
.build()
.unwrap()
);
// Create cache manager
let cache = CacheManager::new(
CacheConfig { max_image_count: 100 },
runtime
);
// Load and cache an image
let image = cache.get_image("path/to/image.jpg").await.unwrap();
println!("Image dimensions: {:?}", image.dimensions());
}
The crate includes two binary tools for testing and benchmarking:
Loads and caches a single image, with detailed timing information:
$ read_image --image test.jpg --detailed
🚀 Starting read_image tool...
📊 Image details:
Dimensions: 1920x1080
Raw file size: 2457600 bytes
Memory size: 8294400 bytes
⏱️ Timing:
First load: 45.2ms
Cache hit: 0.8ms
Speed improvement: 56.5x
Processes and caches all images in a directory with parallel loading:
$ read_directory --directory ./photos --max-images 1000 --verbose
🚀 Starting directory scanner...
📊 Summary:
- Images processed: 50
- Successfully cached: 50
- Total memory usage: 154.2 MB
- Average cache hit time: 0.9ms
max_image_count based on available memory and typical image sizesThe crate provides detailed error types:
CacheError::ImageLoad - File reading or format errorsCacheError::CapacityExceeded - Cache size limitsCacheError::FileSystem - OS-level file operationsCacheError::Config - Configuration issuesContributions welcome! Please check out our Contributing Guide.
MIT License