pub struct SnapshotCache { /* private fields */ }Expand description
Per-thread cached reader for a PublishedSnapshot.
arc_swap::Cache::load is wait-free thread-local-cached: when
the underlying ArcSwap pointer is unchanged, the load is one
Relaxed atomic compare and returns the cached Arc reference
at no further cost. When the pointer changes (post-publish),
the next load reloads the new Arc and caches it.
Per-thread state. Cache is Send but !Sync. Each
reader thread owns its own SnapshotCache; the App’s renderer
thread (the editor mainloop) is the canonical user. Multiple
threads reading the same document each construct their own
cache from clones of the underlying Arc<PublishedSnapshot>.
Backs the §5.6.8 commitment that the read path lives at the hardware floor (~2ns per load) when the writer hasn’t changed the snapshot since the last frame – the common case for a renderer reading multiple times per frame between edits.
Implementations§
Source§impl SnapshotCache
impl SnapshotCache
Sourcepub fn new(cell: Arc<PublishedSnapshot>) -> Self
pub fn new(cell: Arc<PublishedSnapshot>) -> Self
Build a fresh cache from a clone of the published-snapshot
cell. The first load() call pulls the current snapshot;
subsequent calls reuse the cached Arc until the writer
publishes something new.
Sourcepub fn load(&mut self) -> &Arc<DocumentSnapshot> ⓘ
pub fn load(&mut self) -> &Arc<DocumentSnapshot> ⓘ
Wait-free per-thread-cached load. Returns a reference to
the cached Arc<DocumentSnapshot>; clone if the caller
needs an owned Arc. Cheaper than cloning – the
reference is valid for as long as the cache isn’t loaded
again.
Sourcepub fn load_arc(&mut self) -> Arc<DocumentSnapshot> ⓘ
pub fn load_arc(&mut self) -> Arc<DocumentSnapshot> ⓘ
Owned-Arc variant for callers that genuinely need to
store the snapshot beyond the cache’s borrow lifetime.
Costs one Arc bump on top of Self::load; use sparingly.
Trait Implementations§
Source§impl Debug for SnapshotCache
impl Debug for SnapshotCache
Source§impl Default for SnapshotCache
Placeholder cache for Editor::default() headless / test
scaffolding. Backed by a fresh ArcSwap<DocumentSnapshot>
cell carrying a default snapshot. Real construction goes
through SnapshotCache::new from the document’s
PublishedSnapshot::cell_arc(); Editor::new(...)
overwrites this before the first frame.
impl Default for SnapshotCache
Placeholder cache for Editor::default() headless / test
scaffolding. Backed by a fresh ArcSwap<DocumentSnapshot>
cell carrying a default snapshot. Real construction goes
through SnapshotCache::new from the document’s
PublishedSnapshot::cell_arc(); Editor::new(...)
overwrites this before the first frame.