Class BaseCache<TCacheValue>
The BaseCache class implements the overall logic of this cache library and delegates the concrete implementation of how e.g. add, get or remove should work to a derived class.
To use this base class simply override the abstract methods for Add, Get, Put and Remove.
All other methods defined by ICache will be delegated to those methods.
Inheritance
Inherited Members
Namespace:CacheManager.Core.Internal
Assembly:CacheManager.Core.dll
Syntax
public abstract class BaseCache<TCacheValue> : ICache<TCacheValue>, IDisposable
Type Parameters
| Name | Description |
|---|---|
| TCacheValue | The type of the cache value. |
Constructors
| Improve this Doc View SourceBaseCache()
Initializes a new instance of the BaseCache<TCacheValue> class.
Declaration
protected BaseCache()
Properties
| Improve this Doc View SourceDisposed
Gets or sets a value indicating whether this BaseCache<TCacheValue> is disposed.
Declaration
protected bool Disposed { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
Disposing
Gets or sets a value indicating whether this BaseCache<TCacheValue> is disposing.
Declaration
protected bool Disposing { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
Item[String]
Gets or sets a value for the specified key. The indexer is identical to the corresponding Put(String, TCacheValue) and Get(String) calls.
Declaration
public virtual TCacheValue this[string key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
Property Value
| Type | Description |
|---|---|
| TCacheValue | The value being stored in the cache for the given key. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key is null. |
Item[String, String]
Gets or sets a value for the specified key and region. The indexer is identical to the corresponding Put(String, TCacheValue, String) and Get(String, String) calls.
With region specified, the key will not be found in the global cache.
Declaration
public virtual TCacheValue this[string key, string region] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| String | region | The cache region. |
Property Value
| Type | Description |
|---|---|
| TCacheValue | The value being stored in the cache for the given key and region. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |
Logger
Gets the logger.
Declaration
protected abstract ILogger Logger { get; }
Property Value
| Type | Description |
|---|---|
| ILogger | The logger instance. |
Methods
| Improve this Doc View SourceAdd(CacheItem<TCacheValue>)
Adds the specified CacheItem to the cache.
Use this overload to overrule the configured expiration settings of the cache and to define a custom expiration for this item only.
The Add method will not be successful if the specified
item already exists within the cache!
Declaration
public virtual bool Add(CacheItem<TCacheValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | item | The |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the item or the item's key or value is null. |
Add(String, TCacheValue)
Adds a value for the specified key to the cache.
The Add method will not be successful if the specified
key already exists within the cache!
Declaration
public virtual bool Add(string key, TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| TCacheValue | value | The value which should be cached. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or value is null. |
Add(String, TCacheValue, String)
Adds a value for the specified key and region to the cache.
The Add method will not be successful if the specified
key already exists within the cache!
With region specified, the key will not be found in the global cache.
Declaration
public virtual bool Add(string key, TCacheValue value, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| TCacheValue | value | The value which should be cached. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key, value or region is null. |
AddInternal(CacheItem<TCacheValue>)
Adds a value to the cache.
Declaration
protected abstract bool AddInternal(CacheItem<TCacheValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | item | The |
Returns
| Type | Description |
|---|---|
| Boolean |
|
CheckDisposed()
Checks if the instance is disposed.
Declaration
protected void CheckDisposed()
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | If the instance is disposed. |
Clear()
Clears this cache, removing all items in the base cache and all regions.
Declaration
public abstract void Clear()
Implements
| Improve this Doc View SourceClearRegion(String)
Clears the cache region, removing all items from the specified region only.
Declaration
public abstract void ClearRegion(string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | region | The cache region. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the region is null. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Implements
| Improve this Doc View SourceDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
Declaration
protected virtual void Dispose(bool disposeManaged)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | disposeManaged |
|
Exists(String)
Declaration
public abstract bool Exists(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
| Improve this Doc View SourceExists(String, String)
Declaration
public abstract bool Exists(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | |
| String | region |
Returns
| Type | Description |
|---|---|
| Boolean |
Implements
| Improve this Doc View SourceFinalize()
Finalizes an instance of the BaseCache<TCacheValue> class.
Declaration
protected void Finalize()
Get(String)
Gets a value for the specified key.
Declaration
public virtual TCacheValue Get(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value being stored in the cache for the given key. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key is null. |
Get(String, String)
Gets a value for the specified key and region.
Declaration
public virtual TCacheValue Get(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| TCacheValue | The value being stored in the cache for the given key and region. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |
Get<TOut>(String)
Gets a value for the specified key and will cast it to the specified type.
Declaration
public virtual TOut Get<TOut>(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
Returns
| Type | Description |
|---|---|
| TOut | The value being stored in the cache for the given key. |
Type Parameters
| Name | Description |
|---|---|
| TOut | The type the value is converted and returned. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key is null. |
| InvalidCastException | If no explicit cast is defined from |
Get<TOut>(String, String)
Gets a value for the specified key and region and will cast it to the specified type.
Declaration
public virtual TOut Get<TOut>(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| TOut | The value being stored in the cache for the given key and region. |
Type Parameters
| Name | Description |
|---|---|
| TOut | The type the cached value should be converted to. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |
| InvalidCastException | If no explicit cast is defined from |
GetCacheItem(String)
Gets the CacheItem for the specified key.
Declaration
public virtual CacheItem<TCacheValue> GetCacheItem(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
Returns
| Type | Description |
|---|---|
| CacheItem<TCacheValue> | The |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key is null. |
GetCacheItem(String, String)
Gets the CacheItem for the specified key and region.
Declaration
public virtual CacheItem<TCacheValue> GetCacheItem(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| CacheItem<TCacheValue> | The |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |
GetCacheItemInternal(String)
Gets a CacheItem for the specified key.
Declaration
protected abstract CacheItem<TCacheValue> GetCacheItemInternal(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
Returns
| Type | Description |
|---|---|
| CacheItem<TCacheValue> | The |
GetCacheItemInternal(String, String)
Gets a CacheItem for the specified key and region.
Declaration
protected abstract CacheItem<TCacheValue> GetCacheItemInternal(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| CacheItem<TCacheValue> | The |
GetCasted<TOut>(Object)
Casts the value to TOut.
Declaration
protected static TOut GetCasted<TOut>(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | value | The value. |
Returns
| Type | Description |
|---|---|
| TOut | The casted value. |
Type Parameters
| Name | Description |
|---|---|
| TOut | The type. |
Put(CacheItem<TCacheValue>)
Puts the specified CacheItem into the cache.
If the item already exists within the cache, the existing item will be replaced with the new item.
Use this overload to overrule the configured expiration settings of the cache and to define a custom expiration for this item only.
Declaration
public virtual void Put(CacheItem<TCacheValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | item | The |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the item or the item's key or value is null. |
Put(String, TCacheValue)
Puts a value for the specified key into the cache.
If the key already exists within the cache, the existing value will be replaced with the new value.
Declaration
public virtual void Put(string key, TCacheValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| TCacheValue | value | The value which should be cached. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or value is null. |
Put(String, TCacheValue, String)
Puts a value for the specified key and region into the cache.
If the key already exists within the cache, the existing value will be replaced with the new value.
With region specified, the key will not be found in the global cache.
Declaration
public virtual void Put(string key, TCacheValue value, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| TCacheValue | value | The value which should be cached. |
| String | region | The cache region. |
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key, value or region is null. |
PutInternal(CacheItem<TCacheValue>)
Puts a value into the cache.
Declaration
protected abstract void PutInternal(CacheItem<TCacheValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | item | The |
Remove(String)
Removes a value from the cache for the specified key.
Declaration
public virtual bool Remove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key is null. |
Remove(String, String)
Removes a value from the cache for the specified key and region.
Declaration
public virtual bool Remove(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Implements
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |
RemoveInternal(String)
Removes a value from the cache for the specified key.
Declaration
protected abstract bool RemoveInternal(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
RemoveInternal(String, String)
Removes a value from the cache for the specified key and region.
Declaration
protected abstract bool RemoveInternal(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key being used to identify the item within the cache. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| Boolean |
|