示例#1
0
        public CachePerformanceCounters(string cacheName, string handleName, CacheStats <T> stats)
        {
            NotNullOrWhiteSpace(cacheName, nameof(cacheName));

            NotNullOrWhiteSpace(handleName, nameof(handleName));

            string processName = Process.GetCurrentProcess().ProcessName;

            this.instanceName = string.Concat(processName + ":" + cacheName + ":" + handleName);

            var invalidInstanceChars = new string[] { "(", ")", "#", "\\", "/" };

            foreach (var ichar in invalidInstanceChars)
            {
                this.instanceName = this.instanceName.Replace(ichar, string.Empty);
            }

            if (this.instanceName.Length > 128)
            {
                this.instanceName = this.instanceName.Substring(0, 128);
            }

            this.InitializeCounters();
            this.stats       = stats;
            this.statsCounts = new long[NumStatsCounters];

            if (this.enabled)
            {
                this.counterTimer = new Timer(new TimerCallback(this.PerformanceCounterWorker), null, 450L, 450L);
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseCacheHandle{TCacheValue}"/> class.
        /// </summary>
        /// <param name="managerConfiguration">The manager's configuration.</param>
        /// <param name="configuration">The configuration.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="managerConfiguration"/> or <paramref name="configuration"/> are null.
        /// </exception>
        /// <exception cref="System.ArgumentException">If <paramref name="configuration"/> name is empty.</exception>
        protected BaseCacheHandle(IOptions <CacheManagerConfiguration <TKey, TValue> > managerConfiguration,
                                  IOptions <CacheHandleConfiguration> configuration)
        {
            NotNullOrWhiteSpace(configuration.Value.Name, nameof(configuration.Value.Name));

            Configuration = configuration.Value;

            Stats = new CacheStats <TKey, TValue>(
                managerConfiguration.Value.Name,
                Configuration.Name,
                Configuration.EnableStatistics,
                Configuration.EnablePerformanceCounters);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseCacheHandle{TCacheValue}"/> class.
        /// </summary>
        /// <param name="managerConfiguration">The manager's configuration.</param>
        /// <param name="configuration">The configuration.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="managerConfiguration"/> or <paramref name="configuration"/> are null.
        /// </exception>
        /// <exception cref="System.ArgumentException">If <paramref name="configuration"/> name is empty.</exception>
        protected BaseCacheHandle(ICacheManagerConfiguration managerConfiguration, CacheHandleConfiguration configuration)
        {
            NotNull(configuration, nameof(configuration));
            NotNull(managerConfiguration, nameof(managerConfiguration));
            NotNullOrWhiteSpace(configuration.Name, nameof(configuration.Name));

            Configuration = configuration;

            Stats = new CacheStats <TCacheValue>(
                managerConfiguration.Name,
                Configuration.Name,
                Configuration.EnableStatistics,
                Configuration.EnablePerformanceCounters);
        }
示例#4
0
        public CachePerformanceCounters(string cacheName, string handleName, CacheStats <TKey, TValue> stats)
        {
            if (!OperatingSystem.IsWindows())
            {
                throw new NotSupportedException("CachePerformanceCounters is only supported on windows.");
            }

            NotNullOrWhiteSpace(cacheName, nameof(cacheName));

            NotNullOrWhiteSpace(handleName, nameof(handleName));

            var processName = Process.GetCurrentProcess().ProcessName;

            _instanceName = string.Concat(processName + ":" + cacheName + ":" + handleName);

            var invalidInstanceChars = new string[] { "(", ")", "#", "\\", "/" };

            foreach (var ichar in invalidInstanceChars)
            {
                _instanceName = _instanceName.Replace(ichar, string.Empty);
            }

            if (_instanceName.Length > 128)
            {
                _instanceName = _instanceName.Substring(0, 128);
            }

            InitializeCounters();
            _stats       = stats;
            _statsCounts = new long[_numStatsCounters];

            if (_enabled)
            {
                _counterTimer = new Timer(new TimerCallback(PerformanceCounterWorker), null, 450L, 450L);
            }
        }