예제 #1
0
        /// <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);
            }
        }
예제 #2
0
 /// <summary>
 /// Disposes cache.
 /// </summary>
 public void Destroy()
 {
     try
     {
         lock (_caches)
         {
             if (_cacheHandler != null)
             {
                 if (_logger.IsDebugEnabled)
                 {
                     _logger.Debug(String.Format("Destroying Region Cache : {0}", _regionName));
                 }
                 if (_cacheHandler.DecrementRefCount() == 0)
                 {
                     _caches.Remove(_regionConfig.CacheName);
                     _cacheHandler.DisposeCache();
                 }
                 _cacheHandler = null;
             }
         }
     }
     catch (Exception e)
     {
         if (_logger.IsErrorEnabled)
         {
             _logger.Error("Destroy operation failed." + e.Message);
         }
         throw new CacheException("Destroy operation failed." + e.Message, e);
     }
 }