pub struct Cache<A: AtomicArcRef> { /* private fields */ }Expand description
A cache for a shared AtomicArc.
Built as a wrapper around AtomicArc::load_cached,
it essentially makes loads of up-to-date Arcs free, but requires a mutable reference.
As the cache stores the latest loaded Arc, it can delay its reclamation until a new Arc is loaded.
§Examples
let atomic_arc = Arc::new(AtomicArc::<usize>::from(0));
let mut cache = hazarc::Cache::new(atomic_arc);
assert_eq!(**cache.load(), 0);It also works with AtomicOptionArc.
let atomic_arc = Arc::new(AtomicOptionArc::<usize>::none());
let mut cache = hazarc::Cache::new(atomic_arc);
assert_eq!(cache.load(), None);Implementations§
Source§impl<A: AtomicArcRef> Cache<A>
impl<A: AtomicArcRef> Cache<A>
Sourcepub fn into_inner(self) -> A
pub fn into_inner(self) -> A
Consumes the cache to returns the inner shared AtomicArc.
Sourcepub fn load(&mut self) -> A::LoadCached<'_>
pub fn load(&mut self) -> A::LoadCached<'_>
Returns a reference the cached Arc, updating it when it is outdated.
Returns a reference to the cached Arc if it is up-to-date, or loads the latest Arc.
Contrary to load, it doesn’t require a mutable reference; as a consequence,
the cached Arc is not updated when the latest Arc is loaded.
This method is intended for workflows where the atomic Arc is unlikely to be updated after the cache construction.
Trait Implementations§
Source§impl<'de, A: AtomicArcRef + Deserialize<'de>> Deserialize<'de> for Cache<A>
Available on crate feature serde only.
impl<'de, A: AtomicArcRef + Deserialize<'de>> Deserialize<'de> for Cache<A>
serde only.