/// <summary> /// <para> /// Returns the corresponding statistical information of the /// <see cref="CacheStatsCounterType"/> type. /// </para> /// <para> /// If the cache handles is configured to disable statistics, the method will always return zero. /// </para> /// </summary> /// <remarks> /// In multithreaded environments the counters can be changed while reading. Do not rely on /// those counters as they might not be 100% accurate. /// </remarks> /// <example> /// <code> /// <![CDATA[ /// 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) /// )); /// } /// ]]> /// </code> /// </example> /// <param name="type">The stats type to retrieve the number for.</param> /// <returns>A number representing the counts for the specified <see cref="CacheStatsCounterType"/>.</returns> public long GetStatistic(CacheStatsCounterType type) { if (!_isStatsEnabled) { return(0L); } return(_counter.Get(type)); }
/// <summary> /// <para> /// Returns the corresponding statistical information of the /// <see cref="CacheStatsCounterType"/> type. /// </para> /// <para> /// If the cache handles is configured to disable statistics, the method will always return zero. /// </para> /// </summary> /// <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. /// </remarks> /// <example> /// <code> /// <![CDATA[ /// 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) /// )); /// } /// ]]> /// </code> /// </example> /// <param name="type">The stats type to retrieve the number for.</param> /// <param name="region"> /// The region. The returned value will represent the counter of the region only. /// </param> /// <returns> /// A number representing the counts for the specified <see cref="CacheStatsCounterType"/> /// and region. /// </returns> public long GetStatistic(CacheStatsCounterType type, string region) { if (!_isStatsEnabled) { return(0L); } NotNullOrWhiteSpace(region, nameof(region)); var counter = GetCounter(region); return(counter.Get(type)); }
/// <summary> /// <para> /// Returns the corresponding statistical information of the /// <see cref="CacheStatsCounterType"/> type. /// </para> /// <para> /// If the cache handles is configured to disable statistics, the method will always return zero. /// </para> /// </summary> /// <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. /// </remarks> /// <example> /// <code> /// <![CDATA[ /// 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) /// )); /// } /// ]]> /// </code> /// </example> /// <param name="type">The stats type to retrieve the number for.</param> /// <param name="region"> /// The region. The returned value will represent the counter of the region only. /// </param> /// <returns> /// A number representing the counts for the specified <see cref="CacheStatsCounterType"/> /// and region. /// </returns> public long GetStatistic(CacheStatsCounterType type, string region) { if (!this.isStatsEnabled) { return(0L); } if (string.IsNullOrWhiteSpace(region)) { throw new ArgumentNullException("region"); } var counter = this.GetCounter(region); return(counter.Get(type)); }
/// <summary> /// Initializes a new instance of the <see cref="CacheStatistic"/> class. /// </summary> /// <param name="counterType">Type of the counter.</param> /// <param name="count">The count.</param> public CacheStatistic(CacheStatsCounterType counterType, long count) { CounterType = counterType; Count = count; }
public void Add(CacheStatsCounterType type, long value) { Interlocked.Add(ref _counters[(int)type], value); }
public void Set(CacheStatsCounterType type, long value) { Interlocked.Exchange(ref _counters[(int)type], value); }
public void Increment(CacheStatsCounterType type) { Interlocked.Increment(ref _counters[(int)type]); }
public long Get(CacheStatsCounterType type) => _counters[(int)type];
public void Decrement(CacheStatsCounterType type) { Interlocked.Decrement(ref this.counters[(int)type]); }
/// <summary> /// <para> /// Returns the corresponding statistical information of the /// <see cref="CacheStatsCounterType"/> type. /// </para> /// <para> /// If the cache handles is configured to disable statistics, the method will always return zero. /// </para> /// </summary> /// <remarks> /// In multithreaded environments the counters can be changed while reading. Do not rely on /// those counters as they might not be 100% accurate. /// </remarks> /// <example> /// <code> /// <![CDATA[ /// 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) /// )); /// } /// ]]> /// </code> /// </example> /// <param name="type">The stats type to retrieve the number for.</param> /// <returns>A number representing the counts for the specified <see cref="CacheStatsCounterType"/>.</returns> public long GetStatistic(CacheStatsCounterType type) { return(this.GetStatistic(type, NullRegionKey)); }
public void Set(CacheStatsCounterType type, long value) { Interlocked.Exchange(ref this.counters[(int)type], value); }
public void Increment(CacheStatsCounterType type) { Interlocked.Increment(ref this.counters[(int)type]); }
public long Get(CacheStatsCounterType type) { var result = this.counters[(int)type]; return result; }
public void Add(CacheStatsCounterType type, long value) { Interlocked.Add(ref this.counters[(int)type], value); }
public long Get(CacheStatsCounterType type) => this.counters[(int)type];
/// <summary> /// <para> /// Returns the corresponding statistical information of the /// <see cref="CacheStatsCounterType"/> type. /// </para> /// <para> /// If the cache handles is configured to disable statistics, the method will always return zero. /// </para> /// </summary> /// <remarks> /// In multithreaded environments the counters can be changed while reading. Do not rely on /// those counters as they might not be 100% accurate. /// </remarks> /// <example> /// <code> /// <![CDATA[ /// 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) /// )); /// } /// ]]> /// </code> /// </example> /// <param name="type">The stats type to retrieve the number for.</param> /// <returns>A number representing the counts for the specified <see cref="CacheStatsCounterType"/>.</returns> public long GetStatistic(CacheStatsCounterType type) => this.GetStatistic(type, NullRegionKey);
/// <summary> /// <para> /// Returns the corresponding statistical information of the /// <see cref="CacheStatsCounterType"/> type. /// </para> /// <para> /// If the cache handles is configured to disable statistics, the method will always return zero. /// </para> /// </summary> /// <remarks> /// In multithreaded environments the counters can be changed while reading. Do not rely on /// those counters as they might not be 100% accurate. /// </remarks> /// <example> /// <code> /// <![CDATA[ /// 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) /// )); /// } /// ]]> /// </code> /// </example> /// <param name="type">The stats type to retrieve the number for.</param> /// <returns>A number representing the counts for the specified <see cref="CacheStatsCounterType"/>.</returns> public long GetStatistic(CacheStatsCounterType type) => GetStatistic(type, _nullRegionKey);
public long Get(CacheStatsCounterType type) { var result = this.counters[(int)type]; return(result); }