pub struct PrefetchBuffer<S: AsyncRowSource> { /* private fields */ }Expand description
Wraps an AsyncRowSource and provides a synchronous RowSource view.
The buffer caches fetched rows in an LRU cache (capacity max_rows).
On a cache miss it returns a placeholder row of Cell::Empty values and
enqueues the row index for background prefetch. Callers are expected to
drive the prefetch loop by calling flush_pending
in an async context (e.g. a Tokio task or a wasm_bindgen_futures::spawn_local
closure).
§Placeholder row
A cache miss returns N Cell::Empty cells where N is
column_defs().len(). Renderers may style such cells as loading
placeholders (spinner, shimmer, etc.).
§Thread safety
The inner state is wrapped in Arc<Mutex<_>> so PrefetchBuffer is
Send + Sync and can be shared across threads or with async runtimes.
Implementations§
Source§impl<S: AsyncRowSource> PrefetchBuffer<S>
impl<S: AsyncRowSource> PrefetchBuffer<S>
Sourcepub fn new(source: S, max_rows: usize, prefetch_ahead: usize) -> Self
pub fn new(source: S, max_rows: usize, prefetch_ahead: usize) -> Self
Create a new buffer wrapping source.
max_rows: maximum number of rows to hold in the LRU cache.prefetch_ahead: number of rows ahead of the viewport to enqueue for prefetch whenrequest_prefetchis called.
Sourcepub fn request_prefetch(&self, start: usize, viewport_rows: usize)
pub fn request_prefetch(&self, start: usize, viewport_rows: usize)
Request that rows [start, start + viewport_rows + prefetch_ahead) be
prefetched.
Non-cached rows are enqueued internally; call
flush_pending in an async context to
actually perform the fetches.
Sourcepub async fn flush_pending(&self) -> usize
pub async fn flush_pending(&self) -> usize
Drive the prefetch loop, fetching all pending rows and storing them in the cache.
Should be called from an async context (e.g. a spawned task). Returns the number of rows successfully fetched in this call.
Sourcepub fn store_row(&self, index: usize, cells: Vec<Cell>)
pub fn store_row(&self, index: usize, cells: Vec<Cell>)
Store a single already-fetched row directly into the cache.
Useful for callers that manage their own prefetch executor.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Invalidate the entire cache (e.g. after a source mutation).
The next call to RowSource::row will trigger fresh prefetch requests
for every accessed row.
Sourcepub fn cached_count(&self) -> usize
pub fn cached_count(&self) -> usize
Number of rows currently held in the cache.
Trait Implementations§
Source§impl<S: AsyncRowSource> Clone for PrefetchBuffer<S>
impl<S: AsyncRowSource> Clone for PrefetchBuffer<S>
Source§impl<S: AsyncRowSource> RowSource for PrefetchBuffer<S>
impl<S: AsyncRowSource> RowSource for PrefetchBuffer<S>
Source§fn column_defs(&self) -> &[ColumnDef]
fn column_defs(&self) -> &[ColumnDef]
Source§fn set_cell(
&mut self,
_row: usize,
_col: usize,
_value: Cell,
) -> Result<(), TableError>
fn set_cell( &mut self, _row: usize, _col: usize, _value: Cell, ) -> Result<(), TableError>
Auto Trait Implementations§
impl<S> Freeze for PrefetchBuffer<S>
impl<S> RefUnwindSafe for PrefetchBuffer<S>where
S: RefUnwindSafe,
impl<S> Send for PrefetchBuffer<S>where
S: Sync,
impl<S> Sync for PrefetchBuffer<S>where
S: Sync,
impl<S> Unpin for PrefetchBuffer<S>
impl<S> UnsafeUnpin for PrefetchBuffer<S>
impl<S> UnwindSafe for PrefetchBuffer<S>where
S: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more