コード例 #1
0
ファイル: CacheHostEngine.cs プロジェクト: shibukraj/dache
        /// <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);
        }
コード例 #2
0
ファイル: CacheHostEngine.cs プロジェクト: zuiwanting/dache
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="memCache">The mem cache to use.</param>
        /// <param name="logger">The logger to use.</param>
        /// <param name="port">The port to open.</param>
        /// <param name="physicalMemoryLimitPercentage">The cache memory limit, as a percentage of physical memory.</param>
        /// <param name="maximumConnections">The maximum number of simultaneous connections permitted to the cache host.</param>
        /// <param name="messageBufferSize">The message buffer size.</param>
        public CacheHostEngine(IMemCache memCache, ILogger logger, int port, int physicalMemoryLimitPercentage = 85, int maximumConnections = 20, int messageBufferSize = 1024)
        {
            // Sanitize
            if (memCache == null)
            {
                throw new ArgumentNullException("memCache");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (port <= 0)
            {
                throw new ArgumentException("cannot be <= 0", "port");
            }
            if (physicalMemoryLimitPercentage < 5 || physicalMemoryLimitPercentage > 90)
            {
                throw new ArgumentException("must be >= 5 and <= 90", "physicalMemoryLimitPercentage");
            }
            if (maximumConnections <= 0)
            {
                throw new ArgumentException("cannot be <= 0", "maximumConnections");
            }
            if (messageBufferSize < 32 || messageBufferSize > 32768)
            {
                throw new ArgumentException("must be >= 32 and <= 32768", "messageBufferSize");
            }

            // Initialize the tag routing table
            var tagRoutingTable = new TagRoutingTable();

            // Initialize the cache host server
            var cacheHostServer = new CacheHostServer(memCache, tagRoutingTable, logger, port, maximumConnections, messageBufferSize);

            // Instantiate the cache host runner
            _cacheHostRunner = new CacheHostRunner(cacheHostServer);
        }