示例#1
0
        private void Configure(CacheRegionElement settings, IDictionary <string, string> additionalProperties)
        {
            log.Debug("Configuring cache region");

            //these are some default conenction values that can be later used by the data dependencies
            //if no custome settings are specified
            string connectionName   = null;
            string connectionString = null;

            if (additionalProperties != null)
            {
                //pick up connection settings that might be used later for data dependencis if any are specified
                if (additionalProperties.ContainsKey(Environment.ConnectionStringName))
                {
                    connectionName = additionalProperties[Environment.ConnectionStringName];
                }

                if (additionalProperties.ContainsKey(Environment.ConnectionString))
                {
                    connectionString = additionalProperties[Environment.ConnectionString];
                }
            }

            if (settings != null)
            {
                //_priority = settings.Priority;
                _timeOfDayExpiration = settings.TimeOfDayExpiration;
                _relativeExpiration  = settings.RelativeExpiration;

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("using priority: {0}", settings.Priority.ToString("g"));

                    if (_relativeExpiration.HasValue)
                    {
                        log.DebugFormat("using relative expiration :{0}", _relativeExpiration);
                    }

                    if (_timeOfDayExpiration.HasValue)
                    {
                        log.DebugFormat("using time of day expiration : {0}", _timeOfDayExpiration);
                    }
                }

                CreateDependencyEnlisters(settings.Dependencies, connectionName, connectionString);
            }
            else
            {
                _priority = CacheItemPriority.Default;
            }

            if (_relativeExpiration.HasValue == false && _timeOfDayExpiration.HasValue == false)
            {
                _relativeExpiration = defaultRelativeExpiration;
            }
        }
        /// <summary>
        /// Configure the cache
        /// </summary>
        /// <param name="regionName">the name of the cache region</param>
        /// <param name="properties">configuration settings</param>
        /// <returns></returns>
        public ICache BuildCache(string regionName, IDictionary <string, string> properties)
        {
            //return a configured cache region if we have one for the region already
            //the only way this will really happen is if there is a query cache specified for a region that is configured
            //since query caches are not configured at session factory startup
            if (String.IsNullOrEmpty(regionName) == false && cacheRegions.ContainsKey(regionName))
            {
                return(cacheRegions[regionName]);
            }

            //build the cache from preconfigured values if the region has configuration values
            if (cacheRegionSettingsList != null)
            {
                CacheRegionElement regionSettings = cacheRegionSettingsList[regionName];

                if (regionSettings != null)
                {
                    SysCacheRegion cacheRegion;

                    lock (regionsSyncRoot)
                    {
                        //note that the only reason we have to do this double check is because the query cache
                        //can try to create caches at unpredictable times
                        if (cacheRegions.TryGetValue(regionName, out cacheRegion) == false)
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.DebugFormat("building cache region, '{0}', from configuration", regionName);
                            }

                            //build the cache region with settings and put it into the list so that this proces will not occur again
                            cacheRegion = new SysCacheRegion(regionName, regionSettings, properties);
                            cacheRegions[regionName] = cacheRegion;
                        }
                    }

                    return(cacheRegion);
                }
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("building non-configured cache region : {0}", regionName);
            }

            //we will end up creating cache regions here for cache regions that nhibernate
            //uses internally and cache regions that weren't specified in the application config file
            return(new SysCacheRegion(regionName, properties));
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SysCacheRegion"/> class.
        /// </summary>
        /// <param name="name">The name of the region</param>
        /// <param name="settings">The configuration settings for the cache region</param>
        /// <param name="additionalProperties">additional NHibernate configuration properties</param>
        public SysCacheRegion(string name, CacheRegionElement settings, IDictionary <string, string> additionalProperties)
        {
            //validate the params
            if (String.IsNullOrEmpty(name))
            {
                log.Info("No region name specified for cache region. Using default name of 'nhibernate'");
                name = "nhibernate";
            }

            //_webCache = HttpRuntime.Cache;
            _name = name;

            //configure the cache region based on the configured settings and any relevant nhibernate settings
            Configure(settings, additionalProperties);

            //creaet the cache key that will be used for the root cache item which all other
            //cache items are dependent on
            _rootCacheKey = GenerateRootCacheKey();
        }