Expand description
Cross-session persistent cache for decoded thumbnails and media fingerprints.
The in-memory crate::dedup_cache LRU cache is discarded at process exit.
This module adds a lightweight JSON-backed persistent store so that expensive
thumbnail decoding and perceptual hash computation are reused across
deduplication sessions.
§Design
PersistentFingerprintCache maintains a flat JSON file on disk. Each entry
records:
- The source file path.
- Its BLAKE3 hex digest (64 chars) — used to detect when the file changes and the cached fingerprint is stale.
- The 64-bit perceptual hash.
- An optional thumbnail (8×8 grayscale pixel bytes, base64-encoded).
- The modification timestamp at cache time.
On load, all entries are read from disk.
On save, the current entries are written
back atomically (write to a temp file then rename).
Staleness is detected by comparing the stored BLAKE3 digest with a freshly
computed digest of the source file. get_valid
returns None for stale or missing entries.
§Example
use oximedia_dedup::persistent_cache::{PersistentFingerprintCache, CachedEntry};
let dir = std::env::temp_dir().join("oximedia_pc_doctest");
std::fs::create_dir_all(&dir).ok();
let cache_path = dir.join("fps.json");
let mut cache = PersistentFingerprintCache::new(cache_path.clone());
cache.insert(CachedEntry {
path: "/media/clip.mp4".to_string(),
blake3_hex: "0".repeat(64),
phash: 0xDEAD_BEEF_1234_5678,
thumbnail: None,
modified_secs: 1_700_000_000,
});
cache.save().expect("save ok");
let cache2 = PersistentFingerprintCache::load(cache_path).expect("load ok");
assert_eq!(cache2.len(), 1);Structs§
- Cached
Entry - A single entry in the persistent fingerprint cache.
- Persistent
Fingerprint Cache - Cross-session persistent cache mapping file paths to their fingerprints.