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

    Class CacheStats<TCacheValue>

    Stores statistical information for a BaseCacheHandle<TCacheValue>.

    Statistical counters are stored globally for the BaseCacheHandle<TCacheValue> and for each cache region!

    To retrieve a counter for a region only, specify the optional region attribute of GetStatistics.

    Inheritance
    Object
    CacheStats<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 sealed class CacheStats<TCacheValue> : IDisposable
    Type Parameters
    Name Description
    TCacheValue

    Inherited object type of the owning cache handle.

    Remarks

    The class is primarily used internally. Only the GetStatistics is visible. Therefore the class is sealed.

    Constructors

    | Improve this Doc View Source

    CacheStats(String, String, Boolean, Boolean)

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

    Declaration
    public CacheStats(string cacheName, string handleName, bool enabled = true, bool enablePerformanceCounters = false)
    Parameters
    Type Name Description
    String cacheName

    Name of the cache.

    String handleName

    Name of the handle.

    Boolean enabled

    If set to true the stats are enabled. Otherwise any statistics and performance counters will be disabled.

    Boolean enablePerformanceCounters

    If set to true performance counters and statistics will be enabled.

    Exceptions
    Type Condition
    ArgumentNullException

    If cacheName or handleName are null.

    Methods

    | 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

    Finalize()

    Finalizes an instance of the CacheStats<TCacheValue> class.

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

    GetStatistic(CacheStatsCounterType)

    Returns the corresponding statistical information of the CacheStatsCounterType type.

    If the cache handles is configured to disable statistics, the method will always return zero.

    Declaration
    public long GetStatistic(CacheStatsCounterType type)
    Parameters
    Type Name Description
    CacheStatsCounterType type

    The stats type to retrieve the number for.

    Returns
    Type Description
    Int64

    A number representing the counts for the specified CacheStatsCounterType.

    Remarks

    In multithreaded environments the counters can be changed while reading. Do not rely on those counters as they might not be 100% accurate.

    Examples
    var cache = CacheFactory.FromConfiguration("myCache");
    
    foreach (var handle in cache.CacheHandles)
    {
       var stats = handle.Stats;
       Console.WriteLine(string.Format(
               "Items: {0}, Hits: {1}, Miss: {2}, Remove: {3}, ClearRegion: {4}, Clear: {5}, Adds: {6}, Puts: {7}, Gets: {8}",
                   stats.GetStatistic(CacheStatsCounterType.Items),
                   stats.GetStatistic(CacheStatsCounterType.Hits),
                   stats.GetStatistic(CacheStatsCounterType.Misses),
                   stats.GetStatistic(CacheStatsCounterType.RemoveCalls),
                   stats.GetStatistic(CacheStatsCounterType.ClearRegionCalls),
                   stats.GetStatistic(CacheStatsCounterType.ClearCalls),
                   stats.GetStatistic(CacheStatsCounterType.AddCalls),
                   stats.GetStatistic(CacheStatsCounterType.PutCalls),
                   stats.GetStatistic(CacheStatsCounterType.GetCalls)
               ));
    }
    | Improve this Doc View Source

    GetStatistic(CacheStatsCounterType, String)

    Returns the corresponding statistical information of the CacheStatsCounterType type.

    If the cache handles is configured to disable statistics, the method will always return zero.

    Declaration
    public long GetStatistic(CacheStatsCounterType type, string region)
    Parameters
    Type Name Description
    CacheStatsCounterType type

    The stats type to retrieve the number for.

    String region

    The region. The returned value will represent the counter of the region only.

    Returns
    Type Description
    Int64

    A number representing the counts for the specified CacheStatsCounterType and region.

    Remarks

    In multi threaded environments the counters can be changed while reading. Do not rely on those counters as they might not be 100% accurate.

    Examples
    var cache = CacheFactory.FromConfiguration("myCache");
    
    foreach (var handle in cache.CacheHandles)
    {
       var stats = handle.Stats;
       var region = "myRegion";
       Console.WriteLine(string.Format(
               "Items: {0}, Hits: {1}, Miss: {2}, Remove: {3}, ClearRegion: {4}, Clear: {5}, Adds: {6}, Puts: {7}, Gets: {8}",
                   stats.GetStatistic(CacheStatsCounterType.Items, region),
                   stats.GetStatistic(CacheStatsCounterType.Hits, region),
                   stats.GetStatistic(CacheStatsCounterType.Misses, region),
                   stats.GetStatistic(CacheStatsCounterType.RemoveCalls, region),
                   stats.GetStatistic(CacheStatsCounterType.ClearRegionCalls, region),
                   stats.GetStatistic(CacheStatsCounterType.ClearCalls, region),
                   stats.GetStatistic(CacheStatsCounterType.AddCalls, region),
                   stats.GetStatistic(CacheStatsCounterType.PutCalls, region),
                   stats.GetStatistic(CacheStatsCounterType.GetCalls, region)
               ));
    }
    | Improve this Doc View Source

    OnAdd(CacheItem<TCacheValue>)

    Called when an item gets added to the cache.

    Declaration
    public void OnAdd(CacheItem<TCacheValue> item)
    Parameters
    Type Name Description
    CacheItem<TCacheValue> item

    The item.

    Exceptions
    Type Condition
    ArgumentNullException

    If item is null.

    | Improve this Doc View Source

    OnClear()

    Called when the cache got cleared.

    Declaration
    public void OnClear()
    | Improve this Doc View Source

    OnClearRegion(String)

    Called when a cache region got cleared.

    Declaration
    public void OnClearRegion(string region)
    Parameters
    Type Name Description
    String region

    The region.

    | Improve this Doc View Source

    OnGet(String)

    Called when cache Get got invoked.

    Declaration
    public void OnGet(string region = null)
    Parameters
    Type Name Description
    String region

    The region.

    | Improve this Doc View Source

    OnHit(String)

    Called when a Get was successful.

    Declaration
    public void OnHit(string region = null)
    Parameters
    Type Name Description
    String region

    The region.

    | Improve this Doc View Source

    OnMiss(String)

    Called when a Get was not successful.

    Declaration
    public void OnMiss(string region = null)
    Parameters
    Type Name Description
    String region

    The region.

    | Improve this Doc View Source

    OnPut(CacheItem<TCacheValue>, Boolean)

    Called when an item got updated.

    Declaration
    public void OnPut(CacheItem<TCacheValue> item, bool itemAdded)
    Parameters
    Type Name Description
    CacheItem<TCacheValue> item

    The item.

    Boolean itemAdded

    If true the item didn't exist and has been added.

    Exceptions
    Type Condition
    ArgumentNullException

    If item is null.

    | Improve this Doc View Source

    OnRemove(String)

    Called when an item has been removed from the cache.

    Declaration
    public void OnRemove(string region = null)
    Parameters
    Type Name Description
    String region

    The region.

    | Improve this Doc View Source

    OnUpdate(String, String, UpdateItemResult<TCacheValue>)

    Called when an item has been updated.

    Declaration
    public void OnUpdate(string key, string region, UpdateItemResult<TCacheValue> result)
    Parameters
    Type Name Description
    String key

    The key.

    String region

    The region.

    UpdateItemResult<TCacheValue> result

    The result.

    Exceptions
    Type Condition
    ArgumentNullException

    If key or result are null.

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