private void ValidateRegionConfig(RegionConfiguration region) { if (string.IsNullOrEmpty(region.RegionName)) throw new ConfigurationException("region-name cannot be null or empty."); if (string.IsNullOrEmpty(region.CacheName)) throw new ConfigurationException("cache-name cannot be null in region = " + region.RegionName); region.ExpirationType = region.ExpirationType.ToLower(); if(region.ExpirationType!="absolute" && region.ExpirationType!="sliding" && region.ExpirationType!="none") throw new ConfigurationException("Invalid value for expiraion-type in region = " + region.RegionName); if (region.ExpirationType != "none") { if(region.ExpirationPeriod<=0) throw new ConfigurationException("Invalid value for expiraion-period in region = " + region.RegionName + ". Expiraion period must be greater than zero."); } region.Priority = region.Priority.ToLower(); switch (region.Priority) { case "abovenormal": region.CacheItemPriority = Alachisoft.NCache.Runtime.CacheItemPriority.AboveNormal; break; case "belownormal": region.CacheItemPriority = Alachisoft.NCache.Runtime.CacheItemPriority.BelowNormal; break; case "default": region.CacheItemPriority = Alachisoft.NCache.Runtime.CacheItemPriority.Default; break; case "high": region.CacheItemPriority = Alachisoft.NCache.Runtime.CacheItemPriority.High; break; case "low": region.CacheItemPriority = Alachisoft.NCache.Runtime.CacheItemPriority.Low; break; case "normal": region.CacheItemPriority = Alachisoft.NCache.Runtime.CacheItemPriority.Normal; break; case "notremovable": region.CacheItemPriority = Alachisoft.NCache.Runtime.CacheItemPriority.NotRemovable; break; default: throw new ConfigurationException("Invalid value for priority in region = " + region.RegionName); } }
/// <summary> /// Initializes new cache region. /// </summary> /// <param name="regionName">Name of region.</param> /// <param name="properties"></param> public NCache(string regionName, IDictionary<string, string> properties) { try { if (_logger.IsDebugEnabled) { _logger.Debug(String.Format("Initializing NCache with region : {0}", regionName)); } _regionName = regionName; _regionConfig = ConfigurationManager.Instance.GetRegionConfiguration(regionName); lock (_caches) { if (_caches.ContainsKey(_regionConfig.CacheName)) { _cacheHandler = _caches[_regionConfig.CacheName]; _cacheHandler.IncrementRefCount(); } else { _cacheHandler = new CacheHandler(_regionConfig.CacheName, ConfigurationManager.Instance.ExceptionEnabled); _caches.Add(_regionConfig.CacheName, _cacheHandler); } } if (properties["connection.connection_string"] != null) { _connectionString = Convert.ToString(properties["connection.connection_string"]); } } catch (Exception e) { if (_logger.IsErrorEnabled) { _logger.Error("Failed to initialize NCache. " + e.Message); } throw new CacheException("Failed to initialize NCache. "+e.Message,e); } }