Class NonUniqueIndex<TItem, TKey>
- Namespace
- RentADeveloper.AutoIndexCache
- Assembly
- RentADeveloper.AutoIndexCache.dll
A non-unique index for cached items of the type TItem.
public class NonUniqueIndex<TItem, TKey> : INonUniqueIndex<TItem, TKey> where TItem : class
Type Parameters
TItemThe type of cache items indexed by the index.
TKeyThe type of keys in the index.
- Inheritance
-
NonUniqueIndex<TItem, TKey>
- Implements
-
INonUniqueIndex<TItem, TKey>
- Inherited Members
Remarks
All public and protected members of NonUniqueIndex<TItem, TKey> 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 hasGroup1Users = cache.Items<User>().NonUniqueIndex(a => a.GroupId).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.
GetItems(TKey?)
Gets all cached items of the type TItem that have the specified key.
public IReadOnlyList<TItem> GetItems(TKey? condition)
Parameters
conditionTKey
Returns
- IReadOnlyList<TItem>
A read-only list of cached items of the type
TItemthat have the specified key.
Examples
var cache = new AutoIndexCache();
cache.SetItemsLoader<User>(this.LoadUsers);
var usersOfGroup1 = cache.Items<User>().NonUniqueIndex(a => a.GroupId).GetItems(1);
var activeUsersOfGroup10 = cache.Items<User>().NonUniqueIndex(a => new { a.IsActive, a.GroupId}).GetItems(new { IsActive = true, GroupId = 10 });
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.
GetKeys()
Gets the keys in this index.
public IReadOnlyCollection<TKey?> GetKeys()
Returns
- IReadOnlyCollection<TKey>
A read-only collection of the keys in this index.
Examples
var cache = new AutoIndexCache();
cache.SetItemsLoader<User>(this.LoadUsers);
var distinctGroupIds = cache.Items<User>().NonUniqueIndex(a => a.GroupId).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.
Reset()
public void Reset()