Class ItemsList<TItem>
- Namespace
- AutoIndexCache
- Assembly
- AutoIndexCache.dll
A list of cached items of the type TItem
.
Allows to access the cache items of that type, to access unique and non-unique indexes for that type.
public class ItemsList<TItem> : IItemsList<TItem> where TItem : class
Type Parameters
TItem
The type of cached items the list contains.
- Inheritance
-
ItemsList<TItem>
- Implements
-
IItemsList<TItem>
- Inherited Members
Remarks
All public and protected members of ItemsList<TItem> are thread-safe and may be used concurrently from multiple threads.
Methods
Fill(TItem[])
Fills this cache list with the specified items. The specified items will replace all items that are present in this list.
public void Fill(TItem[] items)
Parameters
items
TItem[]The items to fill this list with.
GetAllItems()
Gets all cached items of the type TItem
.
public IReadOnlyList<TItem> GetAllItems()
Returns
- IReadOnlyList<TItem>
A read-only list of all cached items of the type
TItem
.
Examples
var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var users = cache.Items<User>().GetAllItems();
Exceptions
- ItemsListNotFilledYetException
This list has not been filled with items yet.
NonUniqueIndex<TKey>(Func<TItem, TKey?>, string)
Gets a non-unique index for the cached items of the type TItem
.
public INonUniqueIndex<TItem, TKey> NonUniqueIndex<TKey>(Func<TItem, TKey?> keyExpression, string keyExpressionString = "")
Parameters
keyExpression
Func<TItem, TKey>A delegate that gets the index key for each cached item.
keyExpressionString
stringThe string representation of
keyExpression
.
Returns
- INonUniqueIndex<TItem, TKey>
An instance of INonUniqueIndex<TItem, TKey> that provides access to the specified non-unique index.
Type Parameters
TKey
The type of keys in the index.
Examples
var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var usersOfGroup1 = cache.Items<User>().NonUniqueIndex(a => a.GroupId).GetAll(1);
var activeUsersOfGroup10 = cache.Items<User>().NonUniqueIndex(a => new { a.IsActive, a.GroupId}).GetItems(new { IsActive = true, GroupId = 10 });
UniqueIndex<TKey>(Func<TItem, TKey?>, string)
Gets a unique index for the cached items of the type TItem
.
public IUniqueIndex<TItem, TKey> UniqueIndex<TKey>(Func<TItem, TKey?> keyExpression, string keyExpressionString = "")
Parameters
keyExpression
Func<TItem, TKey>A delegate that gets the index key for each cached item.
keyExpressionString
stringThe string representation
keyExpression
.
Returns
- IUniqueIndex<TItem, TKey>
An instance of IUniqueIndex<TItem, TKey> that provides access to the specified unique index.
Type Parameters
TKey
The type of keys in the index.
Examples
var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var user1 = cache.Items<User>().UniqueIndex(a => a.Id).GetItemOrDefault(1);