use hitbox_backend::CacheKeyFormat;
use hitbox_core::CacheKey;
fn main() {
let key = CacheKey::from_slice(&[
("method", Some("GET")),
("path", Some("/api/users/123")),
("tenant", Some("acme-corp")),
]);
println!("Original CacheKey: {:?}\n", key);
let bitcode_format = CacheKeyFormat::Bitcode;
let bincode_serialized = bitcode_format.serialize(&key).unwrap();
println!("Bincode format ({} bytes):", bincode_serialized.len());
println!(" (binary data, not human-readable)");
let bincode_deserialized = bitcode_format.deserialize(&bincode_serialized).unwrap();
assert_eq!(key, bincode_deserialized);
println!(" ✓ Roundtrip successful!");
let urlencoded_format = CacheKeyFormat::UrlEncoded;
let urlencoded_serialized = urlencoded_format.serialize(&key).unwrap();
println!(
"\nURL-encoded format ({} bytes):\n {}",
urlencoded_serialized.len(),
String::from_utf8_lossy(&urlencoded_serialized)
);
println!("\n=== Use Case Recommendations ===");
println!("• Bincode: Redis, Tarantool, high-performance backends (most compact, default)");
println!("• URL-encoded: HTTP caches, CDN keys, query parameters (one-way serialization)");
}