/// <summary> /// The constructor. /// </summary> /// <param name="physicalMemoryLimitPercentage">The cache memory limit, as a percentage of the total system memory.</param> /// <param name="performanceDataManager">The performance data manager.</param> internal MemCache(int physicalMemoryLimitPercentage, PerformanceDataManager performanceDataManager) { // Sanitize if (physicalMemoryLimitPercentage <= 0) { throw new ArgumentException("cannot be <= 0", "physicalMemoryLimitPercentage"); } if (performanceDataManager == null) { throw new ArgumentNullException("performanceDataManager"); } var cacheMemoryLimitMegabytes = (int)(((double)physicalMemoryLimitPercentage / 100) * (new ComputerInfo().TotalPhysicalMemory / 1048576)); // bytes / (1024 * 1024) for MB; _cacheName = "Dache"; _cacheConfig = new NameValueCollection(); _cacheConfig.Add("pollingInterval", "00:00:05"); _cacheConfig.Add("cacheMemoryLimitMegabytes", cacheMemoryLimitMegabytes.ToString()); _cacheConfig.Add("physicalMemoryLimitPercentage", physicalMemoryLimitPercentage.ToString()); _memoryCache = new TrimmingMemoryCache(_cacheName, _cacheConfig); _internDictionary = new Dictionary<string, string>(100); _internReferenceDictionary = new Dictionary<string, int>(100); _performanceDataManager = performanceDataManager; // Configure per second timer to fire every 1000 ms starting 1000ms from now _perSecondTimer = new Timer(PerSecondOperations, null, 1000, 1000); }
/// <summary> /// The constructor. /// </summary> /// <param name="configuration">The configuration to use for the cache host.</param> public CacheHostEngine(CacheHostConfigurationSection configuration) { // Sanitize if (configuration == null) { throw new ArgumentNullException("configuration"); } // Set default logger to file if necessary if (CustomLoggerLoader.DefaultLogger == null) { CustomLoggerLoader.DefaultLogger = new FileLogger(); } var port = configuration.Port; var physicalMemoryLimitPercentage = configuration.CacheMemoryLimitPercentage; var maximumConnections = configuration.MaximumConnections; // Configure the performance counter data manager PerformanceDataManager performanceDataManager = null; try { performanceDataManager = new PerformanceCounterPerformanceDataManager(port); } catch (InvalidOperationException) { // Performance counters aren't installed, so don't use them performanceDataManager = new PerformanceDataManager(); } // Determine the MemCache to use IMemCache memCache = new MemCache(physicalMemoryLimitPercentage, performanceDataManager); if (configuration.CompressData) { memCache = new GZipMemCache(memCache); } // Initialize the tag routing table var tagRoutingTable = new TagRoutingTable(); // Initialize the cache host server var cacheHostServer = new CacheHostServer(memCache, tagRoutingTable, CustomLoggerLoader.LoadLogger(), configuration.Port, configuration.MaximumConnections, configuration.MessageBufferSize, configuration.CommunicationTimeoutSeconds * 1000, configuration.MaximumMessageSizeKB * 1024); // Instantiate the cache host runner _cacheHostRunner = new CacheHostRunner(cacheHostServer); }