pub struct MediaCache { /* private fields */ }Expand description
A bounded decode cache.
Bounded by total decoded bytes rather than entry count: entries differ in size by orders of magnitude, so counting them bounds nothing that matters. Eviction is oldest-inserted-first, which is the right default for a document being read top to bottom.
Implementations§
Source§impl MediaCache
impl MediaCache
pub fn new(budget_bytes: usize) -> Self
Sourcepub async fn get(
self: &Arc<Self>,
path: &Path,
target: (u32, u32),
format: PixelFormat,
) -> Result<Arc<DecodedImage>, MediaError>
pub async fn get( self: &Arc<Self>, path: &Path, target: (u32, u32), format: PixelFormat, ) -> Result<Arc<DecodedImage>, MediaError>
Decoded pixels for path at target, decoding on a blocking thread if
they are not cached.
spawn_blocking, not spawn: the editor actor runs on a
current_thread runtime, so a plain spawn would land the decode on
the actor thread and stall exactly what this crate exists to protect.
Auto Trait Implementations§
impl !Freeze for MediaCache
impl RefUnwindSafe for MediaCache
impl Send for MediaCache
impl Sync for MediaCache
impl Unpin for MediaCache
impl UnsafeUnpin for MediaCache
impl UnwindSafe for MediaCache
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
Mutably borrows from an owned value. Read more