Interface ICacheManager<TCacheValue>
This interface extends the ICache interface by some cache manager specific methods and events.
Inherited Members
Namespace:CacheManager.Core
Assembly:CacheManager.Core.dll
Syntax
public interface ICacheManager<TCacheValue> : ICache<TCacheValue>, IDisposable
Type Parameters
| Name | Description |
|---|---|
| TCacheValue | The type of the cache item value. |
Properties
| Improve this Doc View SourceCacheHandles
Gets a list of cache handles currently registered within the cache manager.
Declaration
IEnumerable<BaseCacheHandle<TCacheValue>> CacheHandles { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<BaseCacheHandle<TCacheValue>> | The cache handles. |
Remarks
This list is read only, any changes to the returned list instance will not affect the state of the cache manager instance.
Configuration
Gets the configuration.
Declaration
IReadOnlyCacheManagerConfiguration Configuration { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyCacheManagerConfiguration | The configuration. |
Name
Gets the cache name.
Declaration
string Name { get; }
Property Value
| Type | Description |
|---|---|
| String | The cache name. |
Methods
| Improve this Doc View SourceAddOrUpdate(CacheItem<TCacheValue>, Func<TCacheValue, TCacheValue>)
Adds an item to the cache or, if the item already exists, updates the item using the updateValue function.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue AddOrUpdate(CacheItem<TCacheValue> addItem, Func<TCacheValue, TCacheValue> updateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | addItem | The item which should be added or updated. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update, if the item does exist. |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value which has been added or updated, or null, if the update was not successful. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If addItem or updateValue are null. |
AddOrUpdate(CacheItem<TCacheValue>, Func<TCacheValue, TCacheValue>, Int32)
Adds an item to the cache or, if the item already exists, updates the item using the updateValue function.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue AddOrUpdate(CacheItem<TCacheValue> addItem, Func<TCacheValue, TCacheValue> updateValue, int maxRetries)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | addItem | The item which should be added or updated. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update, if the item does exist. |
| Int32 | maxRetries | The number of tries which should be performed in case of version conflicts.
If the cache cannot perform an update within the number of maxRetries,
this method will return |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value which has been added or updated, or null, if the update was not successful. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If addItem or updateValue is null. |
AddOrUpdate(String, TCacheValue, Func<TCacheValue, TCacheValue>)
Adds an item to the cache or, if the item already exists, updates the item using the updateValue function.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue AddOrUpdate(string key, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| TCacheValue | addValue | The value which should be added in case the item doesn't already exist. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update in case the item does already exist. |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value which has been added or updated, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or updateValue are null. |
AddOrUpdate(String, TCacheValue, Func<TCacheValue, TCacheValue>, Int32)
Adds an item to the cache or, if the item already exists, updates the item using the updateValue function.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue AddOrUpdate(string key, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue, int maxRetries)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| TCacheValue | addValue | The value which should be added in case the item doesn't already exist. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update in case the item does already exist. |
| Int32 | maxRetries | The number of tries which should be performed in case of version conflicts.
If the cache cannot perform an update within the number of maxRetries,
this method will return |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value which has been added or updated, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or updateValue is null. |
AddOrUpdate(String, String, TCacheValue, Func<TCacheValue, TCacheValue>)
Adds an item to the cache or, if the item already exists, updates the item using the updateValue function.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue AddOrUpdate(string key, string region, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| String | region | The region of the key to update. |
| TCacheValue | addValue | The value which should be added in case the item doesn't already exist. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update in case the item does already exist. |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value which has been added or updated, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or region or updateValue are null. |
AddOrUpdate(String, String, TCacheValue, Func<TCacheValue, TCacheValue>, Int32)
Adds an item to the cache or, if the item already exists, updates the item using the updateValue function.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue AddOrUpdate(string key, string region, TCacheValue addValue, Func<TCacheValue, TCacheValue> updateValue, int maxRetries)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| String | region | The region of the key to update. |
| TCacheValue | addValue | The value which should be added in case the item doesn't already exist. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update in case the item does already exist. |
| Int32 | maxRetries | The number of tries which should be performed in case of version conflicts.
If the cache cannot perform an update within the number of maxRetries,
this method will return |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value which has been added or updated, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or region or updateValue is null. |
Expire(String, ExpirationMode, TimeSpan)
Explicitly sets the expiration mode and timeout for the key in all cache layers. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void Expire(string key, ExpirationMode mode, TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| ExpirationMode | mode | The expiration mode. |
| TimeSpan | timeout | The expiration timeout. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
Expire(String, DateTimeOffset)
Explicitly sets an absolute expiration date for the key in all cache layers. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void Expire(string key, DateTimeOffset absoluteExpiration)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| DateTimeOffset | absoluteExpiration | The expiration date. The value must be greater than zero. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
Expire(String, String, ExpirationMode, TimeSpan)
Explicitly sets the expiration mode and timeout for the key in region in all cache layers. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void Expire(string key, string region, ExpirationMode mode, TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| String | region | The cache region. |
| ExpirationMode | mode | The expiration mode. |
| TimeSpan | timeout | The expiration timeout. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
Expire(String, String, DateTimeOffset)
Explicitly sets an absolute expiration date for the key in region in all cache layers. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void Expire(string key, string region, DateTimeOffset absoluteExpiration)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| String | region | The cache region. |
| DateTimeOffset | absoluteExpiration | The expiration date. The value must be greater than zero. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
Expire(String, String, TimeSpan)
Explicitly sets a sliding expiration date for the key in region in all cache layers. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void Expire(string key, string region, TimeSpan slidingExpiration)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| String | region | The cache region. |
| TimeSpan | slidingExpiration | The expiration timeout. The value must be greater than zero. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
Expire(String, TimeSpan)
Explicitly sets a sliding expiration date for the key in all cache layers. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void Expire(string key, TimeSpan slidingExpiration)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| TimeSpan | slidingExpiration | The expiration timeout. The value must be greater than zero. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
GetOrAdd(String, TCacheValue)
Returns an existing item or adds the item to the cache if it does not exist. The method returns either the existing item's value or the newly added value.
Declaration
TCacheValue GetOrAdd(string key, TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| TCacheValue | value | The value which should be added. |
Returns
| Type | Description |
|---|---|
| TCacheValue | Either the added or the existing value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If either key or value is null. |
GetOrAdd(String, Func<String, TCacheValue>)
Returns an existing item or adds the item to the cache if it does not exist. The valueFactory will be evaluated only if the item does not exist.
Declaration
TCacheValue GetOrAdd(string key, Func<string, TCacheValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| Func<String, TCacheValue> | valueFactory | The method which creates the value which should be added. |
Returns
| Type | Description |
|---|---|
| TCacheValue | Either the added or the existing value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If either key or valueFactory is null. |
GetOrAdd(String, String, TCacheValue)
Returns an existing item or adds the item to the cache if it does not exist. The method returns either the existing item's value or the newly added value.
Declaration
TCacheValue GetOrAdd(string key, string region, TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| String | region | The cache region. |
| TCacheValue | value | The value which should be added. |
Returns
| Type | Description |
|---|---|
| TCacheValue | Either the added or the existing value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If either key, region or value is null. |
GetOrAdd(String, String, Func<String, String, TCacheValue>)
Returns an existing item or adds the item to the cache if it does not exist. The valueFactory will be evaluated only if the item does not exist.
Declaration
TCacheValue GetOrAdd(string key, string region, Func<string, string, TCacheValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| String | region | The cache region. |
| Func<String, String, TCacheValue> | valueFactory | The method which creates the value which should be added. |
Returns
| Type | Description |
|---|---|
| TCacheValue | Either the added or the existing value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If either key or valueFactory is null. |
RemoveExpiration(String)
Explicitly removes any expiration settings previously defined for the key in all cache layers and sets the expiration mode to None. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void RemoveExpiration(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
RemoveExpiration(String, String)
Explicitly removes any expiration settings previously defined for the key in region in all cache layers and sets the expiration mode to None. This operation overrides any configured expiration per cache handle for this particular item.
Declaration
void RemoveExpiration(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| String | region | The cache region. |
Remarks
Don't use this in concurrency critical scenarios if you are using distributed caches as
Expire is not atomic;
Expire uses Put(CacheItem<TCacheValue>) to store the item with the new expiration.
TryGetOrAdd(String, Func<String, TCacheValue>, out TCacheValue)
Tries to either retrieve an existing item or add the item to the cache if it does not exist. The valueFactory will be evaluated only if the item does not exist.
Declaration
bool TryGetOrAdd(string key, Func<string, TCacheValue> valueFactory, out TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| Func<String, TCacheValue> | valueFactory | The method which creates the value which should be added. |
| TCacheValue | value | The cache value. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If either key or valueFactory is null. |
TryGetOrAdd(String, String, Func<String, String, TCacheValue>, out TCacheValue)
Tries to either retrieve an existing item or add the item to the cache if it does not exist. The valueFactory will be evaluated only if the item does not exist.
Declaration
bool TryGetOrAdd(string key, string region, Func<string, string, TCacheValue> valueFactory, out TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key. |
| String | region | The cache region. |
| Func<String, String, TCacheValue> | valueFactory | The method which creates the value which should be added. |
| TCacheValue | value | The cache value. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If either key or valueFactory is null. |
TryUpdate(String, Func<TCacheValue, TCacheValue>, out TCacheValue)
Tries to update an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
bool TryUpdate(string key, Func<TCacheValue, TCacheValue> updateValue, out TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
| TCacheValue | value | The updated value, or null, if the update was not successful. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or updateValue are null. |
TryUpdate(String, Func<TCacheValue, TCacheValue>, Int32, out TCacheValue)
Tries to update an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
bool TryUpdate(string key, Func<TCacheValue, TCacheValue> updateValue, int maxRetries, out TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
| Int32 | maxRetries | The number of tries which should be performed in case of version conflicts.
If the cache cannot perform an update within the number of maxRetries,
this method will return |
| TCacheValue | value | The updated value, or null, if the update was not successful. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or updateValue is null. |
TryUpdate(String, String, Func<TCacheValue, TCacheValue>, out TCacheValue)
Tries to update an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
bool TryUpdate(string key, string region, Func<TCacheValue, TCacheValue> updateValue, out TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| String | region | The region of the key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
| TCacheValue | value | The updated value, or null, if the update was not successful. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or region or updateValue are null. |
TryUpdate(String, String, Func<TCacheValue, TCacheValue>, Int32, out TCacheValue)
Tries to update an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
bool TryUpdate(string key, string region, Func<TCacheValue, TCacheValue> updateValue, int maxRetries, out TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| String | region | The region of the key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
| Int32 | maxRetries | The number of tries which should be performed in case of version conflicts.
If the cache cannot perform an update within the number of maxRetries,
this method will return |
| TCacheValue | value | The updated value, or null, if the update was not successful. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or region or updateValue is null. |
Update(String, Func<TCacheValue, TCacheValue>)
Updates an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue Update(string key, Func<TCacheValue, TCacheValue> updateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
Returns
| Type | Description |
|---|---|
| TCacheValue | The updated value, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or updateValue are null. |
Update(String, Func<TCacheValue, TCacheValue>, Int32)
Updates an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue Update(string key, Func<TCacheValue, TCacheValue> updateValue, int maxRetries)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
| Int32 | maxRetries | The number of tries which should be performed in case of version conflicts.
If the cache cannot perform an update within the number of maxRetries,
this method will return |
Returns
| Type | Description |
|---|---|
| TCacheValue | The updated value, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or updateValue is null. |
Update(String, String, Func<TCacheValue, TCacheValue>)
Updates an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue Update(string key, string region, Func<TCacheValue, TCacheValue> updateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| String | region | The region of the key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
Returns
| Type | Description |
|---|---|
| TCacheValue | The updated value, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or region or updateValue are null. |
Update(String, String, Func<TCacheValue, TCacheValue>, Int32)
Updates an existing key in the cache.
The cache manager will make sure the update will always happen on the most recent version.
If version conflicts occur, if for example multiple cache clients try to write the same key, and during the update process, someone else changed the value for the key, the cache manager will retry the operation.
The updateValue function will get invoked on each retry with the most recent value which is stored in cache.
Declaration
TCacheValue Update(string key, string region, Func<TCacheValue, TCacheValue> updateValue, int maxRetries)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key to update. |
| String | region | The region of the key to update. |
| Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
| Int32 | maxRetries | The number of tries which should be performed in case of version conflicts.
If the cache cannot perform an update within the number of maxRetries,
this method will return |
Returns
| Type | Description |
|---|---|
| TCacheValue | The updated value, or null, if the update was not successful. |
Remarks
If the cache does not use a distributed cache system. Update is doing exactly the same as Get plus Put.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If key or region or updateValue is null. |
Events
| Improve this Doc View SourceOnAdd
Occurs when an item was successfully added to the cache.
The event will not get triggered if Add would return false.
Declaration
event EventHandler<CacheActionEventArgs> OnAdd
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheActionEventArgs> |
OnClear
Occurs when Clear gets called, after the cache has been cleared.
Declaration
event EventHandler<CacheClearEventArgs> OnClear
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheClearEventArgs> |
OnClearRegion
Occurs when ClearRegion gets called, after the cache region has been cleared.
Declaration
event EventHandler<CacheClearRegionEventArgs> OnClearRegion
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheClearRegionEventArgs> |
OnGet
Occurs when an item was retrieved from the cache.
The event will only get triggered on cache hit. Misses do not trigger!
Declaration
event EventHandler<CacheActionEventArgs> OnGet
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheActionEventArgs> |
OnPut
Occurs when an item was put into the cache.
Declaration
event EventHandler<CacheActionEventArgs> OnPut
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheActionEventArgs> |
OnRemove
Occurs when an item was successfully removed from the cache.
Declaration
event EventHandler<CacheActionEventArgs> OnRemove
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheActionEventArgs> |
OnRemoveByHandle
Occurs when an item was removed by the cache handle due to expiration or e.g. memory pressure eviction. The Reason property indicates the reason while the Level indicates which handle triggered the event.
Declaration
event EventHandler<CacheItemRemovedEventArgs> OnRemoveByHandle
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheItemRemovedEventArgs> |
OnUpdate
Occurs when an item was successfully updated.
Declaration
event EventHandler<CacheActionEventArgs> OnUpdate
Event Type
| Type | Description |
|---|---|
| EventHandler<CacheActionEventArgs> |