#[cfg(feature = "persist")]
use quickleaf::{Cache, ListProps};
#[cfg(feature = "persist")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let test_file = "test_cache.db";
let _ = std::fs::remove_file(test_file);
println!("Test 1: Creating cache and inserting data...");
{
use std::{thread, time::Duration};
let mut cache = Cache::with_persist(test_file, 100)?;
cache.insert("key1", "value1");
cache.insert("key2", "value2");
cache.insert("key3", "value3");
println!("Inserted 3 items");
thread::sleep(Duration::from_secs(2));
}
println!("\nTest 2: Loading cache from file...");
{
use std::{thread, time::Duration};
let mut cache = Cache::with_persist(test_file, 100)?;
if let Some(val) = cache.get("key1") {
println!("✓ Found key1: {:?}", val);
} else {
println!("✗ key1 not found!");
}
if let Some(val) = cache.get("key2") {
println!("✓ Found key2: {:?}", val);
} else {
println!("✗ key2 not found!");
}
if let Some(val) = cache.get("key3") {
println!("✓ Found key3: {:?}", val);
} else {
println!("✗ key3 not found!");
}
cache.insert("key4", "value4");
println!("Added key4");
thread::sleep(Duration::from_secs(2));
}
println!("\nTest 3: Final verification...");
{
let mut cache = Cache::with_persist(test_file, 100)?;
let items = cache.list(ListProps::default())?;
println!("Total items in cache: {}", items.len());
for (key, value) in items {
println!(" {} = {:?}", key, value);
}
}
println!("\n✅ Persistence test completed!");
Ok(())
}
#[cfg(not(feature = "persist"))]
fn main() {
println!("This example requires the 'persist' feature");
}