Class SourceCache<TObject, TKey>
- Namespace
- Dynamic
Data
- 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
-
ISource
Cache <TObject, TKey>IObservableCache <TObject, TKey>IConnectableCache <TObject, TKey>
- Extension Methods
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.
Parameters
keySelector
Func<TObject, TKey>The key selector.
Remarks
Initializes a new instance of the SourceCache<TObject, TKey> class.
Exceptions
- Argument
Null Exception keySelector.
Properties
Count
Gets the total count of cached items.
Property Value
Exceptions
- Argument
Null Exception keySelector.
CountChanged
Gets a count changed observable starting with the current count.
Property Value
Exceptions
- Argument
Null Exception keySelector.
Items
Gets the Items.
Property Value
- IRead
Only <TObject>List
Exceptions
- Argument
Null Exception keySelector.
KeySelector
Gets key selector used by the cache to retrieve keys from objects.
Property Value
- Func<TObject, TKey>
Exceptions
- Argument
Null Exception keySelector.
KeyValues
Gets the key value pairs.
Property Value
- IRead
Only <TKey, TObject>Dictionary
Exceptions
- Argument
Null Exception keySelector.
Keys
Gets the keys.
Property Value
- IRead
Only <TKey>List
Exceptions
- Argument
Null Exception 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
boolBy default, empty change sets are not emitted. Set this value to false to emit empty change sets.
Returns
- IObservable<IChange
Set <TObject, TKey>> An observable that emits the change set.
Exceptions
- Argument
Null Exception keySelector.
Dispose()
Exceptions
- Argument
Null Exception 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.
Parameters
updateAction
Action<ISourceUpdater <TObject, TKey>>The update action.
Exceptions
- Argument
Null Exception keySelector.
Lookup(TKey)
Lookup a single item using the specified key.
Parameters
key
TKeyThe key.
Returns
- Optional<TObject>
An optional with the looked up value.
Remarks
Fast indexed lookup.
Exceptions
- Argument
Null Exception 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.
Parameters
Returns
- IObservable<IChange
Set <TObject, TKey>> An observable that emits the change set.
Exceptions
- Argument
Null Exception keySelector.
SuspendCount()
Suspends count notifications.
Returns
- IDisposable
A disposable which when disposed re-activates count notifications.
Exceptions
- Argument
Null Exception keySelector.
SuspendNotifications()
Suspends notifications. When disposed, a reset notification is fired.
Returns
- IDisposable
A disposable which when disposed re-activates notifications.
Exceptions
- Argument
Null Exception 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).
Parameters
key
TKeyThe key.
Returns
- IObservable<Change<TObject, TKey>>
An observable that emits the change set.
Exceptions
- Argument
Null Exception keySelector.