Table of Contents

Class NonUniqueIndex<TItem, TKey>

Namespace
AutoIndexCache
Assembly
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

TItem

The type of cache items indexed by the index.

TKey

The 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

key TKey

The key to check.

Returns

bool

True if this index contains the specified key; otherwise, false.

Examples

var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var hasGroup1Users = cache.Items<User>().NonUniqueIndex(a => a.GroupId).ContainsKey(1);

Exceptions

ItemsListNotFilledYetException

This ItemsList<TItem> this index belongs to has not been filled with items yet.

GetItems(TKey?)

Gets all cached items of the type TItem that satisfy the specified condition.

public IReadOnlyList<TItem> GetItems(TKey? condition)

Parameters

condition TKey

The condition the cache items to get must satisfy.

Returns

IReadOnlyList<TItem>

A read-only list of cached items of the type TItem that satisfy the specified condition.

Examples

var cache = new AutoIndexCache();
cache.Items<User>().Fill(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

ItemsListNotFilledYetException

This ItemsList<TItem> this index belongs to has not been filled with items yet.

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.Items<User>().Fill(this.LoadUsers());
var distinctGroupIds = cache.Items<User>().NonUniqueIndex(a => a.GroupId).GetKeys();

Exceptions

ItemsListNotFilledYetException

This ItemsList<TItem> this index belongs to has not been filled with items yet.

Reset()

public void Reset()