コード例 #1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="module"></param>
        public CacheService(Setting.Setting setting, CacheModule module)
        {
            this.setting = setting;

            this.module = module;

            config = setting.Config;

            //this.memoryDataList = new Store.MemoryDataList(config.MemoryRule.Capacity, config.MemoryRule.ClearSeconds, config.MemoryRule.RemoveSeconds);

            this.lastReadDataList = new Store.LastReadDataList(config.CCLevel, config.LastReadBufferSize);

            this.storeDataList = new Store.StoreDataList(config.CCLevel, config.StoreBufferSize);

            //this.creatingKeyList = new List<string>();

            //this.requestQueue = new RequestQueue();

            this.httpClient = new Common.HttpClient();

            this.httpClient.ReceiveTimeout = config.NetReceiveTimeout;

            this.httpClient.SendTimeout = config.NetSendTimeout;

            if (!string.IsNullOrEmpty(config.ErrorLogPath))
            {
                this.errorLog = new Common.Log(config.ErrorLogPath);

                this.httpClient.ErrorLog = this.errorLog;
            }

            if (!string.IsNullOrEmpty(config.AccessLogPath))
            {
                this.accessLog = new Common.Log(config.AccessLogPath);
            }
        }
コード例 #2
0
ファイル: Config.cs プロジェクト: sdgdsffdsfff/PageCache
        public static bool TryParseConfig(string xmlpath, out Config config)
        {
            config = null;

            bool success = false;

            XmlSerializer serializer = new XmlSerializer(typeof(Config));

            try
            {
                //网络地址
                if (xmlpath.IndexOf("://") > 0)
                {
                    WebClient wc = new WebClient();
                    byte[] data = wc.DownloadData(xmlpath);
                    wc.Dispose();

                    using (MemoryStream stream = new MemoryStream(data))
                    {
                        stream.Seek(0, SeekOrigin.Begin);

                        config = (Config)serializer.Deserialize(stream);

                        success = true;

                        stream.Close();
                        stream.Dispose();
                    }

                }
                else
                {
                    //本地
                    if (File.Exists(xmlpath))
                    {
                        using (var fs = File.OpenRead(xmlpath))
                        {
                            config = (Config)serializer.Deserialize(fs);
                            success = true;

                            fs.Close();
                            fs.Dispose();
                        }
                    }
                }

            }
            catch (Exception ex)
            {

            }

            if (success)
            {

                if (string.IsNullOrEmpty(config.StatusKey))
                {
                    config.StatusKey = "__status__";
                }

                if (config.LastReadBufferSize <= 0)
                {
                    config.LastReadBufferSize = 1000;
                }

                if (config.StoreBufferSize <= 0)
                {
                    config.StoreBufferSize = 100;
                }

                if (config.CCLevel <= 0)
                {

                    config.CCLevel = 5;
                }
            }

            return success;
        }