# SourceCacheEx

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-dynamic-data/cache/trait-sourcecacheex/

**trait** · [`ferroui-dynamic-data`](/docs/0.5.0/api/ferroui-dynamic-data/) · v0.5.0

```rust
trait SourceCacheEx<T: Clone + 'static, K: Eq + Hash + Clone + 'static>: IObservableCache<T, K>
```

The operators and edit conveniences of caches (`SourceCacheEx`, and the extension methods of
`ObservableCacheEx` on `IObservableCache` and `ISourceCache`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L17)

## Members

- [`cast_cache`](#function-cast_cache)
- [`add_or_update`](#function-add_or_update)
- [`add_or_update_with_comparer`](#function-add_or_update_with_comparer)
- [`add_or_update_items`](#function-add_or_update_items)
- [`add_or_update_items_with_comparer`](#function-add_or_update_items_with_comparer)
- [`clear`](#function-clear)
- [`defer_until_loaded`](#function-defer_until_loaded)
- [`edit_diff`](#function-edit_diff)
- [`expire_after`](#function-expire_after)
- [`expire_after_on`](#function-expire_after_on)
- [`expire_after_with_polling`](#function-expire_after_with_polling)
- [`expire_after_with_polling_on`](#function-expire_after_with_polling_on)
- [`limit_size_to`](#function-limit_size_to)
- [`limit_size_to_on`](#function-limit_size_to_on)
- [`populate_from`](#function-populate_from)
- [`populate_from_many`](#function-populate_from_many)
- [`refresh`](#function-refresh)
- [`refresh_items`](#function-refresh_items)
- [`refresh_all`](#function-refresh_all)
- [`remove`](#function-remove)
- [`remove_items`](#function-remove_items)
- [`remove_key`](#function-remove_key)
- [`remove_keys`](#function-remove_keys)
- [`watch_value`](#function-watch_value)

<a id="function-cast_cache"></a>

### cast_cache

```rust
fn cast_cache<U: Clone + 'static>(self: &Self, converter: impl Fn(&T) -> U + 'static) -> Rc<dyn ferroui_system::IObservable<ChangeSet<U, K>>>
```

The items and their changes, each item converted by `converter`
(`Cast(IObservableCache<TSource, TKey>, Func<TSource, TDestination>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L20)

<a id="function-add_or_update"></a>

### add_or_update

```rust
fn add_or_update(self: &Self, item: T)
where Self: crate::cache::ISourceCache<T, K>
```

Adds `item`, or replaces the item of its key (`AddOrUpdate(TObject)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L24)

<a id="function-add_or_update_with_comparer"></a>

### add_or_update_with_comparer

```rust
fn add_or_update_with_comparer(self: &Self, item: T, equality_comparer: impl Fn(&T, &T) -> bool)
where Self: crate::cache::ISourceCache<T, K>
```

`add_or_update` that leaves an equal item, by `equality_comparer`,
as it is (`AddOrUpdate(TObject, IEqualityComparer<TObject>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L24)

<a id="function-add_or_update_items"></a>

### add_or_update_items

```rust
fn add_or_update_items(self: &Self, items: impl IntoIterator<Item = T>)
where Self: crate::cache::ISourceCache<T, K>
```

Adds the items, or replaces the items of their keys (`AddOrUpdate(IEnumerable<TObject>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L24)

<a id="function-add_or_update_items_with_comparer"></a>

### add_or_update_items_with_comparer

```rust
fn add_or_update_items_with_comparer(self: &Self, items: impl IntoIterator<Item = T>, equality_comparer: impl Fn(&T, &T) -> bool)
where Self: crate::cache::ISourceCache<T, K>
```

`add_or_update_items` that leaves the equal items, by
`equality_comparer`, as they are (`AddOrUpdate(IEnumerable<TObject>,
IEqualityComparer<TObject>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L24)

<a id="function-clear"></a>

### clear

```rust
fn clear(self: &Self)
where Self: crate::cache::ISourceCache<T, K>
```

Removes every item (`Clear(ISourceCache)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L25)

<a id="function-defer_until_loaded"></a>

### defer_until_loaded

```rust
fn defer_until_loaded(self: &Self) -> std::rc::Rc<dyn ferroui_system::IObservable<crate::cache::ChangeSet<T, K>>>
```

The items and their changes once the cache has items (`DeferUntilLoaded(IObservableCache)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L26)

<a id="function-edit_diff"></a>

### edit_diff

```rust
fn edit_diff(self: &Self, all_items: impl IntoIterator<Item = T>, are_items_equal: impl Fn(&T, &T) -> bool)
where Self: crate::cache::ISourceCache<T, K>
```

Makes the cache hold `all_items` with the fewest changes: the items whose keys are gone
are removed, the new keys added, and the items that `are_items_equal` says differ updated
(`EditDiff(IEnumerable<TObject>, Func<TObject, TObject, bool>)` and
`EditDiff(IEnumerable<TObject>, IEqualityComparer<TObject>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L27)

<a id="function-expire_after"></a>

### expire_after

```rust
fn expire_after(self: &Self, time_selector: impl Fn(&T) -> Option<std::time::Duration> + 'static) -> std::rc::Rc<dyn ferroui_system::IObservable<Vec<(K, T)>>>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

Removes each item from the cache once the time that `time_selector` gives for it has
passed (`None`: never), timed on the default scheduler; the removed items with their keys
(`ExpireAfter(ISourceCache, Func<TObject, TimeSpan?>, TimeSpan? = null, IScheduler? =
null)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L28)

<a id="function-expire_after_on"></a>

### expire_after_on

```rust
fn expire_after_on(self: &Self, time_selector: impl Fn(&T) -> Option<std::time::Duration> + 'static, scheduler: std::rc::Rc<dyn ferroui_reactive::concurrency::IScheduler>) -> std::rc::Rc<dyn ferroui_system::IObservable<Vec<(K, T)>>>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

`expire_after` on `scheduler`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L28)

<a id="function-expire_after_with_polling"></a>

### expire_after_with_polling

```rust
fn expire_after_with_polling(self: &Self, time_selector: impl Fn(&T) -> Option<std::time::Duration> + 'static, polling_interval: Option<std::time::Duration>) -> std::rc::Rc<dyn ferroui_system::IObservable<Vec<(K, T)>>>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

`expire_after` that removes the expired items every
`polling_interval` rather than at their times.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L28)

<a id="function-expire_after_with_polling_on"></a>

### expire_after_with_polling_on

```rust
fn expire_after_with_polling_on(self: &Self, time_selector: impl Fn(&T) -> Option<std::time::Duration> + 'static, polling_interval: Option<std::time::Duration>, scheduler: std::rc::Rc<dyn ferroui_reactive::concurrency::IScheduler>) -> std::rc::Rc<dyn ferroui_system::IObservable<Vec<(K, T)>>>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

`expire_after_with_polling` on `scheduler`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L28)

<a id="function-limit_size_to"></a>

### limit_size_to

```rust
fn limit_size_to(self: &Self, size_limit: usize) -> std::rc::Rc<dyn ferroui_system::IObservable<Vec<(K, T)>>>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

Removes the oldest items of the cache beyond `size_limit`, on the default scheduler; the
removed items with their keys (`LimitSizeTo(ISourceCache, int, IScheduler? = null)`).
## Panics
For a size of zero (`ArgumentException`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L29)

<a id="function-limit_size_to_on"></a>

### limit_size_to_on

```rust
fn limit_size_to_on(self: &Self, size_limit: usize, scheduler: std::rc::Rc<dyn ferroui_reactive::concurrency::IScheduler>) -> std::rc::Rc<dyn ferroui_system::IObservable<Vec<(K, T)>>>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

`limit_size_to` on `scheduler` (`LimitSizeTo(ISourceCache, int,
IScheduler)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L29)

<a id="function-populate_from"></a>

### populate_from

```rust
fn populate_from(self: &Self, observable: std::rc::Rc<dyn ferroui_system::IObservable<T>>) -> std::rc::Rc<dyn ferroui_system::IDisposable>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

Adds or updates each item of `observable` (`PopulateFrom(IObservable<TObject>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L30)

<a id="function-populate_from_many"></a>

### populate_from_many

```rust
fn populate_from_many<I: IntoIterator<Item = T> + 'static>(self: &Self, observable: std::rc::Rc<dyn ferroui_system::IObservable<I>>) -> std::rc::Rc<dyn ferroui_system::IDisposable>
where Self: crate::cache::ISourceCache<T, K> + Clone + Sized + 'static
```

Adds or updates the items of each collection of `observable`
(`PopulateFrom(IObservable<IEnumerable<TObject>>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L30)

<a id="function-refresh"></a>

### refresh

```rust
fn refresh(self: &Self, item: &T)
where Self: crate::cache::ISourceCache<T, K>
```

Signals that `item` has changed (`Refresh(TObject)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L31)

<a id="function-refresh_items"></a>

### refresh_items

```rust
fn refresh_items(self: &Self, items: impl IntoIterator<Item = T>)
where Self: crate::cache::ISourceCache<T, K>
```

Signals that the items have changed (`Refresh(IEnumerable<TObject>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L31)

<a id="function-refresh_all"></a>

### refresh_all

```rust
fn refresh_all(self: &Self)
where Self: crate::cache::ISourceCache<T, K>
```

Signals that every item has changed (`Refresh()`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L31)

<a id="function-remove"></a>

### remove

```rust
fn remove(self: &Self, item: &T)
where Self: crate::cache::ISourceCache<T, K>
```

Removes the item of the key of `item` (`Remove(TObject)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L32)

<a id="function-remove_items"></a>

### remove_items

```rust
fn remove_items(self: &Self, items: impl IntoIterator<Item = T>)
where Self: crate::cache::ISourceCache<T, K>
```

Removes the items of the keys of `items` (`Remove(IEnumerable<TObject>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L32)

<a id="function-remove_key"></a>

### remove_key

```rust
fn remove_key(self: &Self, key: K)
where Self: crate::cache::ISourceCache<T, K>
```

Removes the item of `key` (`RemoveKey(TKey)`, and `Remove(TKey)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L33)

<a id="function-remove_keys"></a>

### remove_keys

```rust
fn remove_keys(self: &Self, keys: impl IntoIterator<Item = K>)
where Self: crate::cache::ISourceCache<T, K>
```

Removes the items of `keys` (`RemoveKeys(IEnumerable<TKey>)`, and
`Remove(IEnumerable<TKey>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L34)

<a id="function-watch_value"></a>

### watch_value

```rust
fn watch_value(self: &Self, key: K) -> std::rc::Rc<dyn ferroui_system::IObservable<T>>
```

The item of `key` each time it changes (`WatchValue(IObservableCache, TKey)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/cache/source_cache_ex.rs#L35)

## Trait implementations

- [`SourceCacheEx<T, K>`](/docs/0.5.0/api/ferroui-dynamic-data/cache/trait-sourcecacheex/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
