Class LocalCache<TKey, TValue>
Generic key to value cache This class is threadsafe
Inheritance
Implements
Namespace: EPiServer.Data.Cache.Internal
Assembly: EPiServer.Data.dll
Version: 12.0.3Syntax
public class LocalCache<TKey, TValue> : Object, IDisposable
Type Parameters
Name | Description |
---|---|
TKey | The type of key to access the cache |
TValue | The type of value to store in the cache |
Constructors
LocalCache()
Initializes a new instance of the LocalCache<TKey, TValue> class that is empty and has the default initial capacity
Declaration
public LocalCache()
LocalCache(IEqualityComparer<TKey>)
Initializes a new instance of the LocalCache<TKey, TValue> class that is empty and has the equality comparer passed
Declaration
public LocalCache(IEqualityComparer<TKey> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEqualityComparer<TKey> | comparer |
LocalCache(Int32)
Initializes a new instance of the LocalCache<TKey, TValue> class that is empty and has the specified initial capacity
Declaration
public LocalCache(int capacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | The initial number of elements that the LocalCache<TKey, TValue> can contain. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | capacity is less than 0 |
Properties
Item[TKey]
Gets or sets the value associated with the specified key.
Declaration
public virtual TValue this[TKey key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to get or set |
Property Value
Type | Description |
---|---|
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 or overwrites any existing value for the specified key. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | key is null> |
System.Collections.Generic.KeyNotFoundException | The Get operation is called and key does not exist in the collection. |
Methods
Add(TKey, TValue)
Adds the specified key and value to the cache
Declaration
public virtual void Add(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add |
TValue | value | The value of the element to add |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Key is null |
System.ArgumentException | An element with the same key already exists in the cache |
Add(TKey, Boolean, Boolean, Func<TValue>)
Creates a new element or overwrites any existing value for the specified key
Declaration
public virtual TValue Add(TKey key, bool cacheNullValues, bool overwriteExistingValue, Func<TValue> action)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to set |
System.Boolean | cacheNullValues | Specifies if null values returned from the delegate should be stored in the cache |
System.Boolean | overwriteExistingValue | if an existing value in the cache should be updated with the new value, otherwise
|
System.Func<TValue> | action | A delegate to generate the value to set in the cache |
Returns
Type | Description |
---|---|
TValue | The value generated by the delegate |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Key is null |
Clear()
Clears the cache of all keys and values
Declaration
public virtual void Clear()
ContainsKey(TKey)
Determines whether the cache contains the specified key.
Declaration
public virtual bool ContainsKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to locate in the cache |
Returns
Type | Description |
---|---|
System.Boolean | if the cache contains an element with the specified key; otherwise, .
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | key is null> |
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
InternalSet(TKey, TValue)
Declaration
protected virtual void InternalSet(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
TValue | value |
Remove(TKey)
Remove an item from the cache
Declaration
public virtual void Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to remove |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | key is null> |
ShallowCopy()
Does a shallow copy of the items.
Declaration
public Dictionary<TKey, TValue> ShallowCopy()
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<TKey, TValue> | A shallow copy of the items |
TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
Declaration
public virtual bool TryGetValue(TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to get |
TValue | value | 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
Type | Description |
---|---|
System.Boolean | if the cache contains an element with the specified key; otherwise, .
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | key is null> |
ValidateKey(TKey)
Declaration
protected virtual void ValidateKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key |
ValidateValue(TValue)
Declaration
protected virtual void ValidateValue(TValue value)
Parameters
Type | Name | Description |
---|---|---|
TValue | value |