Ejemplo n.º 1
0
        private void InitializeConfiguration(NameValueCollection config)
        {
            MemoryCacheElement element = null;

            if (!_memoryCache.ConfigLess)
            {
                MemoryCacheSection section = ConfigurationManager.GetSection("system.runtime.caching/memoryCache") as MemoryCacheSection;
                if (section != null)
                {
                    element = section.NamedCaches[_memoryCache.Name];
                }
            }

            if (element != null)
            {
                _configCacheMemoryLimitMegabytes     = element.CacheMemoryLimitMegabytes;
                _configPhysicalMemoryLimitPercentage = element.PhysicalMemoryLimitPercentage;
                double milliseconds = element.PollingInterval.TotalMilliseconds;
                _configPollingInterval = (milliseconds < (double)Int32.MaxValue) ? (int)milliseconds : Int32.MaxValue;
            }
            else
            {
                _configPollingInterval               = ConfigUtil.DefaultPollingTimeMilliseconds;
                _configCacheMemoryLimitMegabytes     = 0;
                _configPhysicalMemoryLimitPercentage = 0;
            }

            if (config != null)
            {
                _configPollingInterval               = ConfigUtil.GetIntValueFromTimeSpan(config, ConfigUtil.PollingInterval, _configPollingInterval);
                _configCacheMemoryLimitMegabytes     = ConfigUtil.GetIntValue(config, ConfigUtil.CacheMemoryLimitMegabytes, _configCacheMemoryLimitMegabytes, true, Int32.MaxValue);
                _configPhysicalMemoryLimitPercentage = ConfigUtil.GetIntValue(config, ConfigUtil.PhysicalMemoryLimitPercentage, _configPhysicalMemoryLimitPercentage, true, 100);
            }
        }
Ejemplo n.º 2
0
        private void InitializeConfiguration(NameValueCollection config)
        {
            MemoryCacheElement element = null;

            if (!this._memoryCache.ConfigLess)
            {
                MemoryCacheSection section = ConfigurationManager.GetSection("system.runtime.caching/memoryCache") as MemoryCacheSection;
                if (section != null)
                {
                    element = section.NamedCaches[this._memoryCache.Name];
                }
            }
            if (element != null)
            {
                this._configCacheMemoryLimitMegabytes     = element.CacheMemoryLimitMegabytes;
                this._configPhysicalMemoryLimitPercentage = element.PhysicalMemoryLimitPercentage;
                double totalMilliseconds = element.PollingInterval.TotalMilliseconds;
                this._configPollingInterval = (totalMilliseconds < 2147483647.0) ? ((int)totalMilliseconds) : 0x7fffffff;
            }
            else
            {
                this._configPollingInterval               = 0x1d4c0;
                this._configCacheMemoryLimitMegabytes     = 0;
                this._configPhysicalMemoryLimitPercentage = 0;
            }
            if (config != null)
            {
                this._configPollingInterval               = ConfigUtil.GetIntValueFromTimeSpan(config, "pollingInterval", this._configPollingInterval);
                this._configCacheMemoryLimitMegabytes     = ConfigUtil.GetIntValue(config, "cacheMemoryLimitMegabytes", this._configCacheMemoryLimitMegabytes, true, 0x7fffffff);
                this._configPhysicalMemoryLimitPercentage = ConfigUtil.GetIntValue(config, "physicalMemoryLimitPercentage", this._configPhysicalMemoryLimitPercentage, true, 100);
            }
        }
Ejemplo n.º 3
0
        private void InitializeConfiguration(NameValueCollection config)
        {
            MemoryCacheElement element = null;

            if (!_memoryCache.ConfigLess && _configSupported)
            {
                MemoryCacheSection section = ConfigurationManager.GetSection("system.runtime.caching/memoryCache") as MemoryCacheSection;
                if (section != null)
                {
                    element = section.NamedCaches[_memoryCache.Name];
                }
            }

            if (element != null && _configSupported)
            {
                _configCacheMemoryLimitMegabytes     = element.CacheMemoryLimitMegabytes;
                _configPhysicalMemoryLimitPercentage = element.PhysicalMemoryLimitPercentage;
                double milliseconds = element.PollingInterval.TotalMilliseconds;
                _configPollingInterval = (milliseconds < (double)int.MaxValue) ? (int)milliseconds : int.MaxValue;
            }
            else
            {
                _configPollingInterval               = ConfigUtil.DefaultPollingTimeMilliseconds;
                _configCacheMemoryLimitMegabytes     = 0;
                _configPhysicalMemoryLimitPercentage = 0;
            }

            if (config != null)
            {
                _configPollingInterval               = ConfigUtil.GetIntValueFromTimeSpan(config, ConfigUtil.PollingInterval, _configPollingInterval);
                _configCacheMemoryLimitMegabytes     = ConfigUtil.GetIntValue(config, ConfigUtil.CacheMemoryLimitMegabytes, _configCacheMemoryLimitMegabytes, true, int.MaxValue);
                _configPhysicalMemoryLimitPercentage = ConfigUtil.GetIntValue(config, ConfigUtil.PhysicalMemoryLimitPercentage, _configPhysicalMemoryLimitPercentage, true, 100);
            }
#if !NETCOREAPP
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && _configPhysicalMemoryLimitPercentage > 0)
            {
                throw new PlatformNotSupportedException(SR.PlatformNotSupported_PhysicalMemoryLimitPercentage);
            }
#endif
        }
Ejemplo n.º 4
0
        void GetValuesFromConfig(string name, NameValueCollection config)
        {
            var mcs = ConfigurationManager.GetSection("system.runtime.caching/memoryCache") as MemoryCacheSection;
            MemoryCacheSettingsCollection settings = mcs != null ? mcs.NamedCaches : null;
            MemoryCacheElement            element  = settings != null ? settings [name] : null;

            if (element != null && config == null)
            {
                CacheMemoryLimit    = (long)element.CacheMemoryLimitMegabytes * 1048576L;
                PhysicalMemoryLimit = (long)element.PhysicalMemoryLimitPercentage;
                PollingInterval     = element.PollingInterval;
            }

            if (config != null)
            {
                int parsed;

                if (ParseInt32ConfigValue("config", "cacheMemoryLimitMegabytes", config, Int32.MaxValue, true, out parsed))
                {
                    CacheMemoryLimit = parsed * 1048576L;
                }
                else if (element != null)
                {
                    CacheMemoryLimit = (long)element.CacheMemoryLimitMegabytes * 1048576L;
                }

                if (ParseInt32ConfigValue("config", "physicalMemoryLimitPercentage", config, 100, true, out parsed))
                {
                    PhysicalMemoryLimit = parsed;
                }
                else if (element != null)
                {
                    PhysicalMemoryLimit = (long)element.PhysicalMemoryLimitPercentage;
                }

                TimeSpan ts;
                if (ParseTimeSpanConfigValue("config", "pollingInterval", config, out ts))
                {
                    PollingInterval = ts;
                }
                else if (element != null)
                {
                    PollingInterval = element.PollingInterval;
                }

                // Those are Mono-specific
                if (!String.IsNullOrEmpty(config ["__MonoDisablePerformanceCounters"]))
                {
                    noPerformanceCounters = true;
                }

                if (ParseInt32ConfigValue("config", "__MonoTimerPeriod", config, Int32.MaxValue, false, out parsed))
                {
                    TimerPeriod = (long)(parsed * 1000);
                }
                else
                {
                    TimerPeriod = DEFAULT_TIMER_PERIOD;
                }

                if (ParseBoolConfigValue("config", "__MonoEmulateOneCPU", config, false))
                {
                    emulateOneCPU = true;
                }
            }
            else
            {
                TimerPeriod = DEFAULT_TIMER_PERIOD;
            }

            if (CacheMemoryLimit == 0)
            {
                // Calculated using algorithm described in this blog entry:
                //
                //  http://blogs.msdn.com/tmarq/archive/2007/06/25/some-history-on-the-asp-net-cache-memory-limits.aspx
                //
                ulong physicalRam = TotalPhysicalMemory;
                ulong maxCacheSize;

                // Determine the upper bound
                if (Helpers.Is64Bit)
                {
                    maxCacheSize = 0x10000000000UL;                  // 1TB
                }
                else if (physicalRam > 0x80000000UL)                 // 2GB
                {
                    maxCacheSize = 0x70800000UL;                     // 1800MB
                }
                else
                {
                    maxCacheSize = 0x32000000UL;                     // 800MB
                }
                physicalRam      = (physicalRam * 3) / 5;            // 60%
                CacheMemoryLimit = (long)Math.Min(physicalRam, maxCacheSize);
            }

            if (PhysicalMemoryLimit == 0)
            {
                PhysicalMemoryLimit = 98;
            }

            if (PollingInterval == TimeSpan.Zero)
            {
                PollingInterval = TimeSpan.FromMinutes(2);
            }
        }