pub struct ItemCache<T> { /* private fields */ }
Expand description
A per-item cache.
Cache rendering information for a given item.
Use ItemCache::get_or_update_cache_entry
to get or update the items, the
cache is automatically invalided when the property gets dirty.
ItemCache::component_destroyed
must be called to clear the cache for that
component.
Implementations§
Source§impl<T: Clone> ItemCache<T>
impl<T: Clone> ItemCache<T>
Sourcepub fn get_or_update_cache_entry(
&self,
item_rc: &ItemRc,
update_fn: impl FnOnce() -> T,
) -> T
pub fn get_or_update_cache_entry( &self, item_rc: &ItemRc, update_fn: impl FnOnce() -> T, ) -> T
Returns the cached value associated to the item_rc
if it is still valid.
Otherwise call the update_fn
to compute that value, and track property access
so it is automatically invalided when property becomes dirty.
Sourcepub fn with_entry<U>(
&self,
item_rc: &ItemRc,
callback: impl FnOnce(&T) -> Option<U>,
) -> Option<U>
pub fn with_entry<U>( &self, item_rc: &ItemRc, callback: impl FnOnce(&T) -> Option<U>, ) -> Option<U>
Returns the cached value associated with the item_rc
if it is in the cache
and still valid.
Sourcepub fn clear_cache_if_scale_factor_changed(&self, window: &Window)
pub fn clear_cache_if_scale_factor_changed(&self, window: &Window)
Clears the cache if the window’s scale factor has changed since the last call.
Sourcepub fn component_destroyed(&self, component: ItemTreeRef<'_>)
pub fn component_destroyed(&self, component: ItemTreeRef<'_>)
Function that must be called when a component is destroyed.
Usually can be called from [crate::window::WindowAdapterInternal::unregister_item_tree
]