Class MemoryCacheProvider
Implements the ICacheProvider that stores values in the local memory.
Inherited Members
Namespace: Nevatech.Vsb.Repository.Caching
Assembly: Nevatech.Vsb.Repository.dll
Syntax
public sealed class MemoryCacheProvider : ICacheProvider, IDisposable
Constructors
MemoryCacheProvider()
Declaration
public MemoryCacheProvider()
Fields
CacheName
Name of the cache configuration (used in application configuration file).
Declaration
public const string CacheName = "Nevatech.Vsb.Runtime.MessageCache"
Field Value
| Type | Description |
|---|---|
| string |
Methods
Delete(string)
Deletes a key from cache.
Declaration
[SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockOnObjectsWithWeakIdentity")]
public void Delete(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to delete. |
Dispose()
Releases internal cache.
Declaration
public void Dispose()
GetOrSet<T>(string, Func<T>, Func<T, T>, TimeSpan?, bool)
Gets a value from cache. If value does not exist, it may be optionally created. If it exists, it may be optionally updated. This operation is atomic.
Declaration
[SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockOnObjectsWithWeakIdentity")]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public T GetOrSet<T>(string key, Func<T> createValue = null, Func<T, T> updateValue = null, TimeSpan? expiry = null, bool updateExpiry = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The cache key at which cached string value is stored. |
| Func<T> | createValue | A method returning a new value for caching that is invoked, if cache entry is not found. |
| Func<T, T> | updateValue | A method returning an updated value for caching that is invoked if existing cache entry is found. |
| TimeSpan? | expiry | A timeout on key. After the timeout has expired, the key will automatically be deleted. Setting this value to null will remove the timeout (make key persistent). |
| bool | updateExpiry | True to update existing key expiry to a new value (sliding expiration). The default value is false. |
Returns
| Type | Description |
|---|---|
| T | The cached value or default(T), if cache entry was not found and was not created. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the stored value. |