Table of Contents

Class UniqueIndex<TItem, TKey>

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

TItem

The type of cache items indexed by the index.

TKey

The 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

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 existsUser1 = cache.Items<User>().UniqueIndex(a => a.Id).ContainsKey(1);

Exceptions

ItemsListNotFilledYetException

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

DuplicateKeyException

Multiple cache items of the type TItem have 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

condition TKey

The condition the cache item to get must satisfy.

Returns

TItem

The cached item of the type TItem that satisfies the specified condition or default(TItem) if no such cache item was found.

Examples

var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var user1 = cache.Items<User>().UniqueIndex(a => a.Id).GetItemOrDefault(1);

Exceptions

ItemsListNotFilledYetException

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

DuplicateKeyException

Multiple cache items of the type TItem have 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.Items<User>().Fill(this.LoadUsers());
var usersIds = cache.Items<User>().UniqueIndex(a => a.Id).GetKeys();

Exceptions

ItemsListNotFilledYetException

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

DuplicateKeyException

Multiple cache items of the type TItem have the same key for this unique index.

Reset()

public void Reset()