genswap 0.1.0

Generation-tracked ArcSwap wrapper for 5-1600x faster cached reads in read-heavy workloads
Documentation
//! A generation-tracked wrapper around `ArcSwap` that enables consumers to cache
//! `Arc` references locally and only reload when data has changed.
//!
//! # Overview
//!
//! This library optimizes read-heavy workloads where shared data is updated
//! infrequently. Instead of calling `ArcSwap::load_full()` on every access
//! (which involves atomic refcount operations), consumers check a cheap atomic
//! generation counter first and only reload when necessary.
//!
//! # Example
//!
//! ```
//! use genswap::GenSwap;
//! use std::sync::Arc;
//! use std::thread;
//!
//! // Shared config that gets updated periodically
//! let config = Arc::new(GenSwap::new(42u64));
//!
//! // Spawn consumer threads
//! let handles: Vec<_> = (0..4).map(|_| {
//!     let config = Arc::clone(&config);
//!     thread::spawn(move || {
//!         let mut reader = config.reader();
//!
//!         for _ in 0..1000 {
//!             let value = reader.get();
//!             // Use value - hot path: just an atomic load + comparison
//!             assert!(**value >= 42);
//!         }
//!     })
//! }).collect();
//!
//! for h in handles {
//!     h.join().unwrap();
//! }
//! ```

mod generational_swap;
mod cached_reader;

pub use generational_swap::GenSwap;
pub use cached_reader::CachedReader;

#[cfg(test)]
mod tests;