Class BaseCacheHandle<TCacheValue>
The BaseCacheHandle
implements all the logic which might be common for all the cache
handles. It abstracts the ICache<TCacheValue> interface and defines new properties and
methods the implementer must use.
Actually it is not advisable to not use BaseCacheHandle<TCacheValue>.
Inherited Members
Namespace:CacheManager.Core.Internal
Assembly:CacheManager.Core.dll
Syntax
public abstract class BaseCacheHandle<TCacheValue> : BaseCache<TCacheValue>, ICache<TCacheValue>, IDisposable
Type Parameters
Name | Description |
---|---|
TCacheValue | The type of the cache value. |
Constructors
| Improve this Doc View SourceBaseCacheHandle(ICacheManagerConfiguration, CacheHandleConfiguration)
Initializes a new instance of the BaseCacheHandle<TCacheValue> class.
Declaration
protected BaseCacheHandle(ICacheManagerConfiguration managerConfiguration, CacheHandleConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
ICacheManagerConfiguration | managerConfiguration | The manager's configuration. |
CacheHandleConfiguration | configuration | The configuration. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If managerConfiguration or configuration are null. |
ArgumentException | If configuration name is empty. |
Properties
| Improve this Doc View SourceConfiguration
Gets the cache handle configuration.
Declaration
public CacheHandleConfiguration Configuration { get; }
Property Value
Type | Description |
---|---|
CacheHandleConfiguration | The configuration. |
Count
Gets the number of items the cache handle currently maintains.
Declaration
public abstract int Count { get; }
Property Value
Type | Description |
---|---|
Int32 | The count. |
IsDistributedCache
Indicates if this cache handle is a distributed cache.
Declaration
public virtual bool IsDistributedCache { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
The value will be evaluated by the backplane logic to figure out what to do if remote events are received.
If the cache handle is distributed, a remote remove event for example does not cause another Remove
call.
For in-memory cache handles which are backplane source though, it would trigger a Remove
.
Stats
Gets the cache stats object.
Declaration
public virtual CacheStats<TCacheValue> Stats { get; }
Property Value
Type | Description |
---|---|
CacheStats<TCacheValue> | The stats. |
Methods
| Improve this Doc View SourceAddInternal(CacheItem<TCacheValue>)
Adds a value to the cache.
Declaration
protected override bool AddInternal(CacheItem<TCacheValue> item)
Parameters
Type | Name | Description |
---|---|---|
CacheItem<TCacheValue> | item | The |
Returns
Type | Description |
---|---|
Boolean |
|
Overrides
AddInternalPrepared(CacheItem<TCacheValue>)
Adds a value to the cache.
Declaration
protected abstract bool AddInternalPrepared(CacheItem<TCacheValue> item)
Parameters
Type | Name | Description |
---|---|---|
CacheItem<TCacheValue> | item | The |
Returns
Type | Description |
---|---|
Boolean |
|
Dispose(Boolean)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
protected override void Dispose(bool disposeManaged)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposeManaged | Indicator if managed resources should be released. |
Overrides
GetItemExpiration(CacheItem<TCacheValue>)
Gets the item expiration.
Declaration
protected virtual CacheItem<TCacheValue> GetItemExpiration(CacheItem<TCacheValue> item)
Parameters
Type | Name | Description |
---|---|---|
CacheItem<TCacheValue> | item | The item. |
Returns
Type | Description |
---|---|
CacheItem<TCacheValue> | Returns the updated cache item. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If item is null. |
InvalidOperationException | If expiration mode is defined without timeout. |
PutInternal(CacheItem<TCacheValue>)
Puts the item into the cache. If the item exists it will get updated with the new value. If the item doesn't exist, the item will be added to the cache.
Declaration
protected override void PutInternal(CacheItem<TCacheValue> item)
Parameters
Type | Name | Description |
---|---|---|
CacheItem<TCacheValue> | item | The |
Overrides
PutInternalPrepared(CacheItem<TCacheValue>)
Puts the item into the cache. If the item exists it will get updated with the new value. If the item doesn't exist, the item will be added to the cache.
Declaration
protected abstract void PutInternalPrepared(CacheItem<TCacheValue> item)
Parameters
Type | Name | Description |
---|---|---|
CacheItem<TCacheValue> | item | The |
TriggerCacheSpecificRemove(String, String, CacheItemRemovedReason, Object)
Can be used to signal a remove event to the ICacheManager<TCacheValue> in case the underlying cache supports this and the implementation can react on evictions and expiration of cache items.
Declaration
protected void TriggerCacheSpecificRemove(string key, string region, CacheItemRemovedReason reason, object value)
Parameters
Type | Name | Description |
---|---|---|
String | key | The cache key. |
String | region | The cache region. Can be null. |
CacheItemRemovedReason | reason | The reason. |
Object | value | The original cache value. The value might be null if the underlying cache system doesn't support returning the value on eviction. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If key is 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
public virtual UpdateItemResult<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. |
Returns
Type | Description |
---|---|
UpdateItemResult<TCacheValue> | The update result which is interpreted by the cache manager. |
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>, 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
public virtual UpdateItemResult<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 cache region. |
Func<TCacheValue, TCacheValue> | updateValue | The function to perform the update. |
Int32 | maxRetries | The number of tries. |
Returns
Type | Description |
---|---|
UpdateItemResult<TCacheValue> | The update result which is interpreted by the cache manager. |
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, region or updateValue is null. |