Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheStats{TCacheValue}"/> class.
        /// </summary>
        /// <param name="cacheName">Name of the cache.</param>
        /// <param name="handleName">Name of the handle.</param>
        /// <param name="enabled">
        /// If set to <c>true</c> the stats are enabled. Otherwise any statistics and performance
        /// counters will be disabled.
        /// </param>
        /// <param name="enablePerformanceCounters">
        /// If set to <c>true</c> performance counters and statistics will be enabled.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// If cacheName or handleName are null.
        /// </exception>
        public CacheStats(string cacheName, string handleName, bool enabled = true, bool enablePerformanceCounters = false)
        {
            if (string.IsNullOrWhiteSpace(cacheName))
            {
                throw new ArgumentNullException("cacheName");
            }

            if (string.IsNullOrWhiteSpace(handleName))
            {
                throw new ArgumentNullException("handleName");
            }

            this.lockObject = new object();

            // if performance counters are enabled, stats must be enabled, too.
            this.isStatsEnabled = enablePerformanceCounters ? true : enabled;
            this.isPerformanceCounterEnabled = enablePerformanceCounters;
            this.counters = new ConcurrentDictionary <string, CacheStatsCounter>();

#if !PORTABLE
            if (this.isPerformanceCounterEnabled)
            {
                this.performanceCounters = new CachePerformanceCounters <TCacheValue>(cacheName, handleName, this);
            }
#endif
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheStats{TCacheValue}"/> class.
        /// </summary>
        /// <param name="cacheName">Name of the cache.</param>
        /// <param name="handleName">Name of the handle.</param>
        /// <param name="enabled">
        /// If set to <c>true</c> the stats are enabled. Otherwise any statistics and performance
        /// counters will be disabled.
        /// </param>
        /// <param name="enablePerformanceCounters">
        /// If set to <c>true</c> performance counters and statistics will be enabled.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// If cacheName or handleName are null.
        /// </exception>
        public CacheStats(string cacheName, string handleName, bool enabled = true, bool enablePerformanceCounters = false)
        {
            NotNullOrWhiteSpace(cacheName, nameof(cacheName));
            NotNullOrWhiteSpace(handleName, nameof(handleName));

            // if performance counters are enabled, stats must be enabled, too.
            _isStatsEnabled = enablePerformanceCounters || enabled;
            _isPerformanceCounterEnabled = enablePerformanceCounters;
            _counter = new CacheStatsCounter();

            if (_isPerformanceCounterEnabled)
            {
                _performanceCounters = new CachePerformanceCounters <TKey, TValue>(cacheName, handleName, this);
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheStats{TCacheValue}"/> class.
        /// </summary>
        /// <param name="cacheName">Name of the cache.</param>
        /// <param name="handleName">Name of the handle.</param>
        /// <param name="enabled">
        /// If set to <c>true</c> the stats are enabled. Otherwise any statistics and performance
        /// counters will be disabled.
        /// </param>
        /// <param name="enablePerformanceCounters">
        /// If set to <c>true</c> performance counters and statistics will be enabled.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// If cacheName or handleName are null.
        /// </exception>
        public CacheStats(string cacheName, string handleName, bool enabled = true, bool enablePerformanceCounters = false)
        {
            NotNullOrWhiteSpace(cacheName, nameof(cacheName));
            NotNullOrWhiteSpace(handleName, nameof(handleName));

            // if performance counters are enabled, stats must be enabled, too.
            _isStatsEnabled = enablePerformanceCounters ? true : enabled;
            _isPerformanceCounterEnabled = enablePerformanceCounters;
            _counters = new ConcurrentDictionary <string, CacheStatsCounter>();

            if (_isPerformanceCounterEnabled)
            {
                _performanceCounters = new CachePerformanceCounters <TCacheValue>(cacheName, handleName, this);
            }
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheStats{TCacheValue}"/> class.
        /// </summary>
        /// <param name="cacheName">Name of the cache.</param>
        /// <param name="handleName">Name of the handle.</param>
        /// <param name="enabled">
        /// If set to <c>true</c> the stats are enabled. Otherwise any statistics and performance
        /// counters will be disabled.
        /// </param>
        /// <param name="enablePerformanceCounters">
        /// If set to <c>true</c> performance counters and statistics will be enabled.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// If cacheName or handleName are null.
        /// </exception>
        public CacheStats(string cacheName, string handleName, bool enabled = true, bool enablePerformanceCounters = false)
        {
            NotNullOrWhiteSpace(cacheName, nameof(cacheName));
            NotNullOrWhiteSpace(handleName, nameof(handleName));

            this.lockObject = new object();

            // if performance counters are enabled, stats must be enabled, too.
            this.isStatsEnabled = enablePerformanceCounters ? true : enabled;
            this.isPerformanceCounterEnabled = enablePerformanceCounters;
            this.counters = new Dictionary <string, CacheStatsCounter>();

#if !PORTABLE && !DOTNET5_2
            if (this.isPerformanceCounterEnabled)
            {
                this.performanceCounters = new CachePerformanceCounters <TCacheValue>(cacheName, handleName, this);
            }
#endif
        }