# MemoizingMRUCache

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-splat/logging/struct-memoizingmrucache/

**struct** · [`ferroui-splat`](/docs/0.5.0/api/ferroui-splat/) · v0.5.0

```rust
struct MemoizingMRUCache<K, V>
```

A cache of the values of a function, which keeps the most recently used ones
(`MemoizingMRUCache<TParam, TVal>`): `get` returns the cached value of a key, or computes it
and evicts the least recently used value when the cache is full. Evicted and invalidated values
are handed to the release function.

Keys compare with `PartialEq` or with a comparer (`IEqualityComparer<TParam>`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L51)

## Members

- [`new`](#function-new)
- [`with_release`](#function-with_release)
- [`with_comparer`](#function-with_comparer)
- [`with_release_and_comparer`](#function-with_release_and_comparer)
- [`get`](#function-get)
- [`get_with_context`](#function-get_with_context)
- [`try_get`](#function-try_get)
- [`invalidate`](#function-invalidate)
- [`invalidate_all`](#function-invalidate_all)
- [`invalidate_all_with`](#function-invalidate_all_with)
- [`cached_values`](#function-cached_values)

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

### new

```rust
fn new(calculation_func: impl Fn(&K, Option<&dyn Any>) -> V + 'static, max_size: usize) -> Self
```

A cache of `calculation_func` with at most `max_size` values
(`MemoizingMRUCache(Func<TParam, object?, TVal>, int)`).

Panics when `max_size` is 0 (`ArgumentOutOfRangeException`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L64)

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

### with_release

```rust
fn with_release(calculation_func: impl Fn(&K, Option<&dyn Any>) -> V + 'static, max_size: usize, on_release: impl Fn(V) -> () + 'static) -> Self
```

A cache that hands evicted and invalidated values to `on_release`
(`MemoizingMRUCache(Func<TParam, object?, TVal>, int, Action<TVal>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L70)

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

### with_comparer

```rust
fn with_comparer(calculation_func: impl Fn(&K, Option<&dyn Any>) -> V + 'static, max_size: usize, param_comparer: impl Fn(&K, &K) -> bool + 'static) -> Self
```

A cache whose keys compare with `param_comparer`
(`MemoizingMRUCache(Func<TParam, object?, TVal>, int, IEqualityComparer<TParam>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L82)

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

### with_release_and_comparer

```rust
fn with_release_and_comparer(calculation_func: impl Fn(&K, Option<&dyn Any>) -> V + 'static, max_size: usize, on_release: Option<impl Fn(V) -> () + 'static>, param_comparer: impl Fn(&K, &K) -> bool + 'static) -> Self
```

A cache with a release function and a comparer of keys
(`MemoizingMRUCache(Func<TParam, object?, TVal>, int, Action<TVal>?,
IEqualityComparer<TParam>)`).

Panics when `max_size` is 0 (`ArgumentOutOfRangeException`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L95)

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

### get

```rust
fn get(self: &Self, key: K) -> V
```

The value of `key`, computed on a miss (`Get(TParam)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L136)

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

### get_with_context

```rust
fn get_with_context(self: &Self, key: K, context: Option<&dyn Any>) -> V
```

The value of `key`, computed with `context` on a miss (`Get(TParam, object?)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L141)

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

### try_get

```rust
fn try_get(self: &Self, key: &K) -> Option<V>
```

The cached value of `key`, without computing it (`TryGet`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L182)

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

### invalidate

```rust
fn invalidate(self: &Self, key: &K)
```

Removes `key` and releases its value (`Invalidate`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L187)

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

### invalidate_all

```rust
fn invalidate_all(self: &Self)
```

Removes every value and releases them; a panic of the release function stops the release
(`InvalidateAll()`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L206)

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

### invalidate_all_with

```rust
fn invalidate_all_with(self: &Self, aggregate_release_exceptions: bool) -> Result<(), AggregateReleaseError>
```

Removes every value and releases them (`InvalidateAll(bool)`). With
`aggregate_release_exceptions`, every value is released even when the release function
panics, and the panics are returned together; otherwise the first panic propagates.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L214)

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

### cached_values

```rust
fn cached_values(self: &Self) -> Vec<V>
```

The cached values (`CachedValues`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Splat/logging/memoizing_mru_cache.rs#L251)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`

## Availability

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