コード例 #1
0
        /// <summary>
        /// Reads the configuration related to the set of configured
        /// providers and sets the default and collection of providers and settings.
        /// </summary>
        public static void Initialize()
        {
            CacheProviderConfiguration configSection = (CacheProviderConfiguration)ConfigurationManager.GetSection("CacheProviders");

            if (configSection == null)
#pragma warning disable CS0618 // Type or member is obsolete
            {
                throw new ConfigurationException("Data provider section is not set.");
            }
#pragma warning restore CS0618 // Type or member is obsolete

            _providerCollection = new CacheProviderCollection();
            ProvidersHelper.InstantiateProviders(configSection.Providers, _providerCollection, typeof(CacheProviderBase));

            _providerSettings = configSection.Providers;

            if (_providerCollection[configSection.DefaultProviderName] == null)
#pragma warning disable CS0618 // Type or member is obsolete
            {
                throw new ConfigurationException("Default data provider is not set.");
            }
#pragma warning restore CS0618 // Type or member is obsolete

            _default = _providerCollection[configSection.DefaultProviderName];

            var defaultSettings = _providerSettings[configSection.DefaultProviderName];

            _default.SetParameters(defaultSettings.Parameters);
        }
コード例 #2
0
        public override Model.Entities.Portal GetCurrentPortal()
        {
            Model.Entities.Portal portal        = null;
            CacheProviderBase     cacheProvider = null;

            string cacheKey = string.Format("PORTAL:{0}", ApplicationName); // compose the cache key = constant + host

            if (this._caching)
            {
                cacheProvider = CacheProviderManager.Provider;
                portal        = cacheProvider.Get(cacheKey) as Model.Entities.Portal;
            }

            if (portal == null) // if not in cache, request the portal from database
            {
                portal = _portalRepository.GetPortalByUrl(ApplicationName) ?? _portalRepository.GetPortalByAliasUrl(ApplicationName);

                //if portal url was not found in database, look in portal aliases

                if (this._caching && portal != null) // portal was found, cache it
                {
                    cacheProvider.Insert(cacheKey, portal);
                }
            }

            // this will raise a configuration error if a portal is not defined for the current host

            //if (_portal == null)
            //    throw new ProviderException(string.Format("Could not find portal for host '{0}'.", ApplicationName));
            return(portal);
        }
コード例 #3
0
 internal CacheHelper(RuntimeCacheProviderBase httpCacheProvider, CacheProviderBase staticCacheProvider, bool enableCache)
 {
     _httpCache   = httpCacheProvider;
     _staticCache = staticCacheProvider;
     _enableCache = enableCache;
 }