Ejemplo n.º 1
0
 public MemcachedProvider(CacheServerInfo cacheServerInfo)
 {
     _cacheServerInfo = cacheServerInfo;
     MemcachedClient.Setup(cacheServerInfo.CacheType.ToString(), cacheServerInfo.ServerHost.Split(','));
     memcachedClient = MemcachedClient.GetInstance(cacheServerInfo.CacheType.ToString());
     memcachedClient.SendReceiveTimeout = _cacheServerInfo.SendReceiveTimeout;
     memcachedClient.ConnectTimeout = _cacheServerInfo.ConnectTimeout;
     memcachedClient.MinPoolSize = _cacheServerInfo.MinPoolSize;
     memcachedClient.MaxPoolSize = _cacheServerInfo.MaxPoolSize;
     memcachedClient.KeyPrefix = _cacheServerInfo.Region;
 }
Ejemplo n.º 2
0
 public RedisCacheProvider(CacheServerInfo cacheServerInfo)
 {
     _cacheServerInfo = cacheServerInfo;
     var clientManagerConfig = new RedisClientManagerConfig();
     clientManagerConfig.MaxWritePoolSize = (int) cacheServerInfo.MaxPoolSize;
     clientManagerConfig.MaxReadPoolSize = (int) cacheServerInfo.MaxPoolSize;
     clientManagerConfig.AutoStart = true;
     var dictionary = new Dictionary<long, PooledRedisClientManager>
     {
         {0, new PooledRedisClientManager(cacheServerInfo.ServerHost.Split(','),cacheServerInfo.ServerHost.Split(','), clientManagerConfig)}
     };
     PooledRedisClientManager.Add(cacheServerInfo.CacheType.ToString(), dictionary);
 }
Ejemplo n.º 3
0
 public static ICacheProvider GenerateCacheProvider(CacheServerInfo configInfo)
 {
     switch (configInfo.CacheType)
     {
         case CacheType.Local:
             return new LocalCacheProvider(configInfo);
         case CacheType.Memcache:
             return new MemcachedProvider(configInfo);
            
         case CacheType.Redis:
             return new RedisCacheProvider(configInfo);
         default:
             throw new QdfException("Error CacheType");
     }
 }
Ejemplo n.º 4
0
        public static void Init()
        {
            var configElement = ConfigManager.LoadConfig();
            var root = configElement.XElement.Element("Caches");
            if(root == null)
                throw new QdfException("CacheStorages node not exists");
            foreach (var ele in root.Elements("Cache"))
            {
                var type = ele.Attribute("type").Value;
                var isEnable = Convert.ToBoolean(ele.Attribute("isEnable").Value);
                var xServerHostEle = ele.Element("ServerHost");
                var xRegionEle = ele.Element("Region");
                var xExpireTime = ele.Element("ExpirationTime");
                var xMaxPoolSize = ele.Element("MaxPoolSize");
                var xMinPoolSize = ele.Element("MinPoolSize");
                var xSendReceiveTimeout = ele.Element("SendReveiveTimeout");
                var xConnectTimeout = ele.Element("ConnectTimeout");

                if (xServerHostEle == null)
                    throw new QdfException("ServerHost node not exists");
                
                var cacheServerInfo = new CacheServerInfo
                {
                    CacheType = (CacheType) Enum.Parse(typeof (CacheType), type),
                    ServerHost = xServerHostEle.Attribute("value").Value,
                    Region = xRegionEle == null ? null: xRegionEle.Attribute("value").Value,
                    DefaulExpirationTime = xExpireTime == null ? new TimeSpan(0, 30, 0) : new TimeSpan(0, int.Parse(xExpireTime.Attribute("value").Value), 0),
                    MaxPoolSize = xMaxPoolSize == null ? 1000 :  uint.Parse(xMaxPoolSize.Attribute("value").Value),
                    MinPoolSize = xMinPoolSize == null ? 10 : uint.Parse(xMinPoolSize.Attribute("value").Value),
                    SendReceiveTimeout = xSendReceiveTimeout == null ? 500 : int.Parse(xSendReceiveTimeout.Attribute("value").Value),
                    ConnectTimeout = xConnectTimeout == null ? 500 : int.Parse(xConnectTimeout.Attribute("value").Value),
                    IsDefault = isEnable,
                };

                if (!CacheServerDictionary.ContainsKey(type))
                    CacheServerDictionary.Add(type, cacheServerInfo);
            }
        }
Ejemplo n.º 5
0
        public LocalCacheProvider(CacheServerInfo serverInfo)
            : this(serverInfo.Region, serverInfo.DefaulExpirationTime)
        {

        }