Table of Contents

Class SourceCache<TObject, TKey>

Namespace
DynamicData
Assembly
DynamicData.dll

An observable cache which exposes an update API. Used at the root of all observable chains.

public sealed class SourceCache<TObject, TKey> : ISourceCache<TObject, TKey>, IObservableCache<TObject, TKey>, IConnectableCache<TObject, TKey>, IDisposable, INotifyCollectionChangedSuspender where TObject : notnull where TKey : notnull

Type Parameters

TObject

The type of the object.

TKey

The type of the key.

Inheritance
SourceCache<TObject, TKey>
Implements
ISourceCache<TObject, TKey>
IObservableCache<TObject, TKey>
IConnectableCache<TObject, TKey>
Extension Methods
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)

Remarks

Initializes a new instance of the SourceCache<TObject, TKey> class.

Constructors

SourceCache(Func<TObject, TKey>)

An observable cache which exposes an update API. Used at the root of all observable chains.

public SourceCache(Func<TObject, TKey> keySelector)

Parameters

keySelector Func<TObject, TKey>

The key selector.

Remarks

Initializes a new instance of the SourceCache<TObject, TKey> class.

Exceptions

ArgumentNullException

keySelector.

Properties

Count

Gets the total count of cached items.

public int Count { get; }

Property Value

int

Exceptions

ArgumentNullException

keySelector.

CountChanged

Gets a count changed observable starting with the current count.

public IObservable<int> CountChanged { get; }

Property Value

IObservable<int>

Exceptions

ArgumentNullException

keySelector.

Items

Gets the Items.

public IEnumerable<TObject> Items { get; }

Property Value

IEnumerable<TObject>

Exceptions

ArgumentNullException

keySelector.

KeySelector

Gets key selector used by the cache to retrieve keys from objects.

public Func<TObject, TKey> KeySelector { get; }

Property Value

Func<TObject, TKey>

Exceptions

ArgumentNullException

keySelector.

KeyValues

Gets the key value pairs.

public IEnumerable<KeyValuePair<TKey, TObject>> KeyValues { get; }

Property Value

IEnumerable<KeyValuePair<TKey, TObject>>

Exceptions

ArgumentNullException

keySelector.

Keys

Gets the keys.

public IEnumerable<TKey> Keys { get; }

Property Value

IEnumerable<TKey>

Exceptions

ArgumentNullException

keySelector.

Methods

Connect(Func<TObject, bool>?, bool)

Returns a filtered stream of cache changes preceded with the initial filtered state.

public IObservable<IChangeSet<TObject, TKey>> Connect(Func<TObject, bool>? predicate = null, bool suppressEmptyChangeSets = true)

Parameters

predicate Func<TObject, bool>

The result will be filtered using the specified predicate.

suppressEmptyChangeSets bool

By default, empty change sets are not emitted. Set this value to false to emit empty change sets.

Returns

IObservable<IChangeSet<TObject, TKey>>

An observable that emits the change set.

Exceptions

ArgumentNullException

keySelector.

Dispose()

public void Dispose()

Exceptions

ArgumentNullException

keySelector.

Edit(Action<ISourceUpdater<TObject, TKey>>)

Action to apply a batch update to a cache. Multiple update methods can be invoked within a single batch operation. These operations are invoked within the cache's lock and is therefore thread safe. The result of the action will produce a single change set.

public void Edit(Action<ISourceUpdater<TObject, TKey>> updateAction)

Parameters

updateAction Action<ISourceUpdater<TObject, TKey>>

The update action.

Exceptions

ArgumentNullException

keySelector.

Lookup(TKey)

Lookup a single item using the specified key.

public Optional<TObject> Lookup(TKey key)

Parameters

key TKey

The key.

Returns

Optional<TObject>

An optional with the looked up value.

Remarks

Fast indexed lookup.

Exceptions

ArgumentNullException

keySelector.

Preview(Func<TObject, bool>?)

Returns a filtered stream of cache changes. Unlike Connect(), the returned observable is not prepended with the caches initial items.

public IObservable<IChangeSet<TObject, TKey>> Preview(Func<TObject, bool>? predicate = null)

Parameters

predicate Func<TObject, bool>

The result will be filtered using the specified predicate.

Returns

IObservable<IChangeSet<TObject, TKey>>

An observable that emits the change set.

Exceptions

ArgumentNullException

keySelector.

SuspendCount()

Suspends count notifications.

public IDisposable SuspendCount()

Returns

IDisposable

A disposable which when disposed re-activates count notifications.

Exceptions

ArgumentNullException

keySelector.

SuspendNotifications()

Suspends notifications. When disposed, a reset notification is fired.

public IDisposable SuspendNotifications()

Returns

IDisposable

A disposable which when disposed re-activates notifications.

Exceptions

ArgumentNullException

keySelector.

Watch(TKey)

Returns an observable of any changes which match the specified key. The sequence starts with the initial item in the cache (if there is one).

public IObservable<Change<TObject, TKey>> Watch(TKey key)

Parameters

key TKey

The key.

Returns

IObservable<Change<TObject, TKey>>

An observable that emits the change set.

Exceptions

ArgumentNullException

keySelector.