Table of Contents

Interface IItemsList<TItem>

Namespace
RentADeveloper.AutoIndexCache
Assembly
RentADeveloper.AutoIndexCache.dll

Represents 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 and to reset the list.

public interface IItemsList<TItem> where TItem : class

Type Parameters

TItem

The type of cached items the list contains.

Methods

ForceLoadItems()

Forces this list to load the cache items of the type TItem immediately, using the cache items loader specified for the cache item type TItem.

void ForceLoadItems()

Remarks

Normally cache items are lazily loaded when they are requested from the cache (e.g. when GetAllItems() is called). This method loads the cache items immediately.

GetAllItems()

Gets all cached items of the type TItem.

IReadOnlyList<TItem> GetAllItems()

Returns

IReadOnlyList<TItem>

A read-only list of all cached items of the type TItem.

Examples

var cache = new AutoIndexCache();
cache.SetItemsLoader<User>(this.LoadUsers);
var users = cache.Items<User>().GetAllItems();

Exceptions

ItemsLoaderReturnedNullException

The cache items loader for the cache item type TItem has returned a null reference instead of a list of cache items.

ItemsLoaderFailedException

The cache items loader for the cache item type TItem has thrown an exception.

ItemsAccessedFromInsideItemsLoaderException

An attempt was made to access cache items of the type TItem from inside the cache items loader for that cache item type.

NonUniqueIndex<TKey>(Func<TItem, TKey?>, string)

Gets a non-unique index for the cached items of the type TItem.

INonUniqueIndex<TItem, TKey> NonUniqueIndex<TKey>(Func<TItem, TKey?> keyExpression, string keyExpressionString = "")

Parameters

keyExpression Func<TItem, TKey>

A function that gets the index key for each cached item.

keyExpressionString string

The 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.SetItemsLoader<User>(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 });

Reset()

Removes all cache items of the type TItem from the cache. The next time cache items of the type TItem are requested from the cache, they are loaded again using the cache items loader for that cache item type (SetItemsLoader<TItem>(Func<TItem[]>)).

void Reset()

Examples

var cache = new AutoIndexCache();
cache.SetItemsLoader<User>(this.LoadUsers);
var users = cache.Items<User>().GetAllItems();
cache.Items<User>().Reset();
var updatedUsers = cache.Items<User>().GetAllItems(); // this.LoadUsers will be called again to get the updated list of users.

Exceptions

ItemsAccessedFromInsideItemsLoaderException

An attempt was made to reset the cache items of the type TItem from inside the cache items loader for that cache item type.

UniqueIndex<TKey>(Func<TItem, TKey?>, string)

Gets a unique index for the cached items of the type TItem.

IUniqueIndex<TItem, TKey> UniqueIndex<TKey>(Func<TItem, TKey?> keyExpression, string keyExpressionString = "")

Parameters

keyExpression Func<TItem, TKey>

A function that gets the index key for each cached item.

keyExpressionString string

The 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.SetItemsLoader<User>(this.LoadUsers);
var user1 = cache.Items<User>().UniqueIndex(a => a.Id).GetItemOrDefault(1);