Class UniqueIndex<TItem, TKey>
- Namespace
- RentADeveloper.AutoIndexCache
- Assembly
- RentADeveloper.AutoIndexCache.dll
A unique index for cached items of the type TItem.
public class UniqueIndex<TItem, TKey> : IUniqueIndex<TItem, TKey> where TItem : class
Type Parameters
TItemThe type of cache items indexed by the index.
TKeyThe type of keys in the index.
- Inheritance
-
UniqueIndex<TItem, TKey>
- Implements
-
IUniqueIndex<TItem, TKey>
- Inherited Members
Remarks
All public and protected members of AutoIndexCache are thread-safe and may be used concurrently from multiple threads.
Methods
ContainsKey(TKey?)
Determines whether this index contains the specified key.
public bool ContainsKey(TKey? key)
Parameters
keyTKeyThe key to check.
Returns
- bool
True if this index contains the specified key; otherwise, false.
Examples
var cache = new AutoIndexCache();
cache.SetItemsLoader<User>(() => this.LoadUsers());
var existsUser1 = cache.Items<User>().UniqueIndex(a => a.Id).ContainsKey(1);
Exceptions
- ItemsLoaderReturnedNullException
The cache items loader for the cache item type
TItemhas returned a null reference instead of a list of cache items.- ItemsLoaderFailedException
The cache items loader for the cache item type
TItemhas thrown an exception.- ItemsAccessedFromInsideItemsLoaderException
An attempt was made to access cache items of the type
TItemfrom inside the cache items loader for that cache item type.- DuplicateKeyException
Multiple cache items of the type
TItemhave the same key for this unique index.
GetItemOrDefault(TKey?)
Gets the cached item of the type TItem that satisfies the specified condition or default(TItem) if no such cache item was found.
public TItem? GetItemOrDefault(TKey? condition)
Parameters
conditionTKeyThe condition the cache item to get must satisfy.
Returns
- TItem
The cached item of the type
TItemthat satisfies the specified condition or default(TItem) if no such cache item was found.
Examples
var cache = new AutoIndexCache();
cache.SetItemsLoader<User>(() => this.LoadUsers());
var user1 = cache.Items<User>().UniqueIndex(a => a.Id).GetItemOrDefault(1);
Exceptions
- ItemsLoaderReturnedNullException
The cache items loader for the cache item type
TItemhas returned a null reference instead of a list of cache items.- ItemsLoaderFailedException
The cache items loader for the cache item type
TItemhas thrown an exception.- ItemsAccessedFromInsideItemsLoaderException
An attempt was made to access cache items of the type
TItemfrom inside the cache items loader for that cache item type.- DuplicateKeyException
Multiple cache items of the type
TItemhave the same key for this unique index.
GetKeys()
Gets the keys in this index.
public IReadOnlyCollection<TKey?> GetKeys()
Returns
- IReadOnlyCollection<TKey>
A read-only collection of the keys of this index.
Examples
var cache = new AutoIndexCache();
cache.SetItemsLoader<User>(() => this.LoadUsers());
var usersIds = cache.Items<User>().UniqueIndex(a => a.Id).GetKeys();
Exceptions
- ItemsLoaderReturnedNullException
The cache items loader for the cache item type
TItemhas returned a null reference instead of a list of cache items.- ItemsLoaderFailedException
The cache items loader for the cache item type
TItemhas thrown an exception.- ItemsAccessedFromInsideItemsLoaderException
An attempt was made to access cache items of the type
TItemfrom inside the cache items loader for that cache item type.- DuplicateKeyException
Multiple cache items of the type
TItemhave the same key for this unique index.
Reset()
public void Reset()