Table of Contents

Class Cache<TKey, TValue>

Namespace
Lextm.SharpSnmpLib.Security
Assembly
SharpSnmpLib.dll

Collection for improving performance. Using hashing of key/value pairs. Oldest elements will be removed from the Cache when the capacity of the cache is reached. This class is not thread safe.

public class Cache<TKey, TValue> where TKey : notnull

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Inheritance
Cache<TKey, TValue>
Inherited Members

Constructors

Cache(int)

Caching class for improving performance. Oldest elements are removed as the cache is filled up

public Cache(int initialCapacity)

Parameters

initialCapacity int

Capacity of the cache before oldest elements start to get removed

Properties

Count

Gets the number of key/value pairs contained in the Cache.

public int Count { get; }

Property Value

int

this[TKey]

Gets the value associated with the specified key.

public TValue this[TKey key] { get; }

Parameters

key TKey

The key of the value to get

Property Value

TValue

The value associated with the specified key. If the specified key is not found, a get operation throws a System.Collections.Generic.KeyNotFoundException, and a set operation creates a new element with the specified key.

Exceptions

ArgumentNullException

key is null.

KeyNotFoundException

The property is retrieved and key does not exist in the collection.

Methods

Add(TKey, TValue)

Adds the specified key and value to the dictionary. If the cache has reached its capacity oldest element will be removed automatically

public void Add(TKey key, TValue value)

Parameters

key TKey

The key of the element to add.

value TValue

The value of the element to add.

Exceptions

ArgumentNullException

key is null

ArgumentException

An element with the same key already exists in the Cache

ContainsKey(TKey)

Determines whether the Cache contains the specified key.

public bool ContainsKey(TKey key)

Parameters

key TKey

The key to locate in the Cache

Returns

bool

true if the Cache contains an element with the specified key; otherwise, false.

TryGetValue(TKey, out TValue?)

Gets the value associated with the specified key.

public bool TryGetValue(TKey key, out TValue? value)

Parameters

key TKey

The key of the value to get.

value TValue

When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the Cache contains an element with the specified key; otherwise, false.