• CacheManager
  • Documentation
  • Api Docs
  • MichaCo.net
    Show / Hide Table of Contents

    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
    Object
    BaseCache<TCacheValue>
    BaseCacheManager<TCacheValue>
    BaseCacheHandle<TCacheValue>
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    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 Source

    BaseCache()

    Initializes a new instance of the BaseCache<TCacheValue> class.

    Declaration
    protected BaseCache()

    Properties

    | Improve this Doc View Source

    Disposed

    Gets or sets a value indicating whether this BaseCache<TCacheValue> is disposed.

    Declaration
    protected bool Disposed { get; set; }
    Property Value
    Type Description
    Boolean

    true if disposed; otherwise, false.

    | Improve this Doc View Source

    Disposing

    Gets or sets a value indicating whether this BaseCache<TCacheValue> is disposing.

    Declaration
    protected bool Disposing { get; set; }
    Property Value
    Type Description
    Boolean

    true if disposing; otherwise, false.

    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Item[String]
    Exceptions
    Type Condition
    ArgumentNullException

    If the key is null.

    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Item[String, String]
    Exceptions
    Type Condition
    ArgumentNullException

    If the key or region is null.

    | Improve this Doc View Source

    Logger

    Gets the logger.

    Declaration
    protected abstract ILogger Logger { get; }
    Property Value
    Type Description
    ILogger

    The logger instance.

    Methods

    | Improve this Doc View Source

    Add(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 CacheItem to be added to the cache.

    Returns
    Type Description
    Boolean

    true if the key was not already added to the cache, false otherwise.

    Implements
    ICache<TCacheValue>.Add(CacheItem<TCacheValue>)
    Exceptions
    Type Condition
    ArgumentNullException

    If the item or the item's key or value is null.

    | Improve this Doc View Source

    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

    true if the key was not already added to the cache, false otherwise.

    Implements
    ICache<TCacheValue>.Add(String, TCacheValue)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key or value is null.

    | Improve this Doc View Source

    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

    true if the key was not already added to the cache, false otherwise.

    Implements
    ICache<TCacheValue>.Add(String, TCacheValue, String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key, value or region is null.

    | Improve this Doc View Source

    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 CacheItem to be added to the cache.

    Returns
    Type Description
    Boolean

    true if the key was not already added to the cache, false otherwise.

    | Improve this Doc View Source

    CheckDisposed()

    Checks if the instance is disposed.

    Declaration
    protected void CheckDisposed()
    Exceptions
    Type Condition
    ObjectDisposedException

    If the instance is disposed.

    | Improve this Doc View Source

    Clear()

    Clears this cache, removing all items in the base cache and all regions.

    Declaration
    public abstract void Clear()
    Implements
    ICache<TCacheValue>.Clear()
    | Improve this Doc View Source

    ClearRegion(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
    ICache<TCacheValue>.ClearRegion(String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the region is null.

    | Improve this Doc View Source

    Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

    Declaration
    public void Dispose()
    Implements
    IDisposable.Dispose()
    | Improve this Doc View Source

    Dispose(Boolean)

    Releases unmanaged and - optionally - managed resources.

    Declaration
    protected virtual void Dispose(bool disposeManaged)
    Parameters
    Type Name Description
    Boolean disposeManaged

    true to release both managed and unmanaged resources; false to release only unmanaged resources.

    | Improve this Doc View Source

    Exists(String)

    Declaration
    public abstract bool Exists(string key)
    Parameters
    Type Name Description
    String key
    Returns
    Type Description
    Boolean
    Implements
    ICache<TCacheValue>.Exists(String)
    | Improve this Doc View Source

    Exists(String, String)

    Declaration
    public abstract bool Exists(string key, string region)
    Parameters
    Type Name Description
    String key
    String region
    Returns
    Type Description
    Boolean
    Implements
    ICache<TCacheValue>.Exists(String, String)
    | Improve this Doc View Source

    Finalize()

    Finalizes an instance of the BaseCache<TCacheValue> class.

    Declaration
    protected void Finalize()
    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Get(String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key is null.

    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Get(String, String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key or region is null.

    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Get<TOut>(String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key is null.

    InvalidCastException

    If no explicit cast is defined from TCacheValue to TOut.

    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Get<TOut>(String, String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key or region is null.

    InvalidCastException

    If no explicit cast is defined from TCacheValue to TOut.

    | Improve this Doc View Source

    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 CacheItem.

    Implements
    ICache<TCacheValue>.GetCacheItem(String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key is null.

    | Improve this Doc View Source

    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 CacheItem.

    Implements
    ICache<TCacheValue>.GetCacheItem(String, String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key or region is null.

    | Improve this Doc View Source

    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 CacheItem.

    | Improve this Doc View Source

    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 CacheItem.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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 CacheItem to be cached.

    Implements
    ICache<TCacheValue>.Put(CacheItem<TCacheValue>)
    Exceptions
    Type Condition
    ArgumentNullException

    If the item or the item's key or value is null.

    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Put(String, TCacheValue)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key or value is null.

    | Improve this Doc View Source

    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
    ICache<TCacheValue>.Put(String, TCacheValue, String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key, value or region is null.

    | Improve this Doc View Source

    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 CacheItem to be added to the cache.

    | Improve this Doc View Source

    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

    true if the key was found and removed from the cache, false otherwise.

    Implements
    ICache<TCacheValue>.Remove(String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key is null.

    | Improve this Doc View Source

    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

    true if the key was found and removed from the cache, false otherwise.

    Implements
    ICache<TCacheValue>.Remove(String, String)
    Exceptions
    Type Condition
    ArgumentNullException

    If the key or region is null.

    | Improve this Doc View Source

    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

    true if the key was found and removed from the cache, false otherwise.

    | Improve this Doc View Source

    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

    true if the key was found and removed from the cache, false otherwise.

    • Improve this Doc
    • View Source
    © 2025 by Michael Conrad. All rights reserved. - MichaCo.net