1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! 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();
//! }
//! ```
pub use GenSwap;
pub use CachedReader;