Class Cache<KType, VType>
- Namespace
- ElectricDrill.SoapRpgFramework.Utils
- Assembly
- com.electricdrill.soap-rpg-framework.Runtime.dll
A generic cache class that provides basic caching functionality.
public class Cache<KType, VType>
Type Parameters
KTypeThe type of the keys in the cache.
VTypeThe type of the values in the cache.
- Inheritance
-
objectCache<KType, VType>
Properties
this[KType]
Gets or sets the value for the specified key in the cache.
public VType this[KType key] { get; set; }
Parameters
keyKTypeThe key of the item to get or set.
Property Value
- VType
The value associated with the specified key.
Methods
Get(KType)
Gets the value for the specified key from the cache. If the key is not found, a KeyNotFoundException is thrown.
public VType Get(KType key)
Parameters
keyKTypeThe key of the item to get.
Returns
- VType
The value associated with the specified key.
Exceptions
- KeyNotFoundException
Thrown when the key is not found in the cache.
Has(KType)
Determines whether the cache contains an item with the specified key.
public bool Has(KType key)
Parameters
keyKTypeThe key to locate in the cache.
Returns
- bool
true if the cache contains an item with the key; otherwise, false.
Invalidate(KType)
Invalidates the cache item for the specified key. If key is not found, nothing happens.
public void Invalidate(KType key)
Parameters
keyKTypeThe key of the item to invalidate.
InvalidateAll()
Invalidates all items in the cache.
public void InvalidateAll()
Set(KType, VType)
Sets the value for the specified key in the cache. UPSERT operation.
public void Set(KType key, VType value)
Parameters
keyKTypeThe key of the item to set.
valueVTypeThe value to set for the specified key.
TryGet(KType, out VType)
Tries to get the value for the specified key from the cache.
public bool TryGet(KType key, out VType value)
Parameters
keyKTypeThe key of the item to get.
valueVTypeWhen 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.
Returns
- bool
true if the cache contains an item with the specified key; otherwise, false.