Interface ICache<TCacheValue>
This interface is the base contract for the main stack of this library.
The ICacheHandle and ICacheManager interfaces are derived from ICache,
meaning the method call signature throughout the stack is very similar.
We want the flexibility of having a simple get/put/delete cache up to multiple caches layered on top of each other, still using the same simple and easy to understand interface.
The TCacheValue can, but most not be used in the sense of strongly typing. This
means, you can define and configure a cache for certain object types within your domain. But
you can also use object and store anything you want within the cache. All underlying
cache technologies usually do not care about types of the cache items.
Inherited Members
Namespace:CacheManager.Core
Assembly:CacheManager.Core.dll
Syntax
public interface ICache<TCacheValue> : IDisposable
Type Parameters
| Name | Description |
|---|---|
| TCacheValue | The type of the cache value. |
Properties
| Improve this Doc View SourceItem[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
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. |
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
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. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |
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
bool Add(CacheItem<TCacheValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | item | The |
Returns
| Type | Description |
|---|---|
| Boolean |
|
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
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 |
|
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
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 |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key, value or region is null. |
Clear()
Clears this cache, removing all items in the base cache and all regions.
Declaration
void Clear()
ClearRegion(String)
Clears the cache region, removing all items from the specified region only.
Declaration
void ClearRegion(string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | region | The cache region. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the region is null. |
Exists(String)
Returns a value indicating if the key exists in at least one cache layer configured in CacheManger, without actually retrieving it from the cache.
Declaration
bool Exists(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key to check. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Exists(String, String)
Returns a value indicating if the key in region exists in at least one cache layer configured in CacheManger, without actually retrieving it from the cache (if supported).
Declaration
bool Exists(string key, string region)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The cache key to check. |
| String | region | The cache region. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Get(String)
Gets a value for the specified key.
Declaration
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. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key is null. |
Get(String, String)
Gets a value for the specified key and region.
Declaration
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. |
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
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. |
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
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. |
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
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 |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key is null. |
GetCacheItem(String, String)
Gets the CacheItem for the specified key and region.
Declaration
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 |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |
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
void Put(CacheItem<TCacheValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| CacheItem<TCacheValue> | item | The |
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
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. |
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
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. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key, value or region is null. |
Remove(String)
Removes a value from the cache for the specified key.
Declaration
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 |
|
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
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 |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the key or region is null. |