Class ChangeAwareCache<TObject, TKey>
- Namespace
- DynamicData
- Assembly
- DynamicData.dll
A cache which captures all changes which are made to it. These changes are recorded until CaptureChanges() at which point thw changes are cleared. Used for creating custom operators.
public sealed class ChangeAwareCache<TObject, TKey> : ICache<TObject, TKey>, IQuery<TObject, TKey> where TObject : notnull where TKey : notnull
Type Parameters
TObjectThe value of the cache.
TKeyThe key of the cache.
- Inheritance
-
ChangeAwareCache<TObject, TKey>
- Extension Methods
Constructors
ChangeAwareCache()
Initializes a new instance of the ChangeAwareCache<TObject, TKey> class.
public ChangeAwareCache()
ChangeAwareCache(Dictionary<TKey, TObject>)
Initializes a new instance of the ChangeAwareCache<TObject, TKey> class.
public ChangeAwareCache(Dictionary<TKey, TObject> data)
Parameters
dataDictionary<TKey, TObject>Data to populate the cache with.
ChangeAwareCache(int)
Initializes a new instance of the ChangeAwareCache<TObject, TKey> class.
public ChangeAwareCache(int capacity)
Parameters
capacityintThe capacity of the initial items.
Properties
Count
Gets the count.
public int Count { get; }
Property Value
Items
Gets the items.
public IEnumerable<TObject> Items { get; }
Property Value
- IEnumerable<TObject>
KeyValues
Gets the items together with their keys.
public IEnumerable<KeyValuePair<TKey, TObject>> KeyValues { get; }
Property Value
- IEnumerable<KeyValuePair<TKey, TObject>>
The key values.
Keys
Gets the keys.
public IEnumerable<TKey> Keys { get; }
Property Value
- IEnumerable<TKey>
Methods
Add(TObject, TKey)
Adds the item to the cache without checking whether there is an existing value in the cache.
public void Add(TObject item, TKey key)
Parameters
itemTObjectThe item to add.
keyTKeyThe key to add.
AddOrUpdate(TObject, TKey)
Adds or updates the item using the specified key.
public void AddOrUpdate(TObject item, TKey key)
Parameters
itemTObjectThe item.
keyTKeyThe key.
CaptureChanges()
Create a change set from recorded changes and clears known changes.
public ChangeSet<TObject, TKey> CaptureChanges()
Returns
- ChangeSet<TObject, TKey>
A change set with the key/value changes.
Clear()
Clears all items.
public void Clear()
Clone(IChangeSet<TObject, TKey>)
Clones the cache from the specified changes.
public void Clone(IChangeSet<TObject, TKey> changes)
Parameters
changesIChangeSet<TObject, TKey>The changes.
Lookup(TKey)
Lookup a single item using the specified key.
public Optional<TObject> Lookup(TKey key)
Parameters
keyTKeyThe key.
Returns
- Optional<TObject>
The looked up value.
Remarks
Fast indexed lookup.
Refresh()
Raises an evaluate change for all items in the cache.
public void Refresh()
Refresh(IEnumerable<TKey>)
Raises an evaluate change for the specified keys.
public void Refresh(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>The keys to refresh.
Refresh(TKey)
Raises an evaluate change for the specified key.
public void Refresh(TKey key)
Parameters
keyTKeyThe key.
Remove(IEnumerable<TKey>)
Removes the item matching the specified keys.
public void Remove(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>The keys.
Remove(TKey)
Removes the item matching the specified key.
public void Remove(TKey key)
Parameters
keyTKeyThe key.