Skip to main content

ImageCache

Struct ImageCache 

Source
pub struct ImageCache { /* private fields */ }
Expand description

Caches decoded images to avoid re-decoding on every frame — keyed by file path (or a content hash for byte sources). Wired for real in Phase 27 (Image::paint previously did fs::read + PNG decode on EVERY paint — the former Known-Issues “orphaned ImageCache” entry); paint-time access goes through ImageCache::global.

Unbounded by design for now: it holds each distinct image an app ever shows, which is the same bound the old decode-per-paint had on peak memory. A byte budget + eviction is real follow-up work, tracked with the compositor’s image-texture eviction.

Implementations§

Source§

impl ImageCache

Source

pub fn new() -> Self

Create a new empty cache.

Source

pub fn global() -> &'static Mutex<ImageCache>

The process-wide cache used by Image::paint — same global-service pattern as the scroll-offset channel.

Source

pub fn invalidate(&mut self, path: impl Into<PathBuf>)

Drop the decode for a single path (the rest of the cache survives). The dev asset watcher uses ImageCache::clear for a blanket flush; this is the targeted variant for when only one asset changed.

Source

pub fn get_or_load(&mut self, path: impl Into<PathBuf>) -> Option<DecodedImage>

Return the cached image for path, loading and decoding it on first access. Returns None if the file cannot be read or decoded as PNG.

Source

pub fn get_or_decode_bytes(&mut self, bytes: &[u8]) -> Option<DecodedImage>

Decode-once for byte sources, keyed by a content hash (dims + len + sampled windows — same scheme as the compositor’s texture key).

Source

pub fn len(&self) -> usize

Number of cached entries (path + byte sources).

Source

pub fn is_empty(&self) -> bool

Returns true if the cache holds no entries.

Source

pub fn clear(&mut self)

Remove all cached entries.

Source

pub fn contains(&self, path: impl Into<PathBuf>) -> bool

Returns true if the given path is already in the cache.

Trait Implementations§

Source§

impl Default for ImageCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.