Exemplo n.º 1
0
 /// <summary>
 /// Get cache container that have underlying cache object(s)
 /// </summary>
 /// <param name="settings">output cache settings specified in web.config</param>
 /// <returns></returns>
 public static CacheContainer  GetCacheInstance(OutputCacheSettings settings)
 {
     if (_container == null)
     {
         _container = new CacheContainer(settings);
     }
     _refCount++;
     return(_container);
 }
Exemplo n.º 2
0
        public OutputCacheSettings LoadCacheSettings()
        {
            NCacheSection section       = new NCacheSection();
            XmlNode       ncacheSection = section.NCacheConfigSection;

            OutputCacheSettings outputCacheSettings = new OutputCacheSettings();

            if (ncacheSection != null)
            {
                XmlNode outputCache = ncacheSection.SelectSingleNode("outputCacheSettings");
                if (outputCache != null)
                {
                    if (outputCache.Attributes["cacheName"] != null && outputCache.Attributes["cacheName"].Value != string.Empty)
                    {
                        outputCacheSettings.CacheName = outputCache.Attributes["cacheName"].Value.ToLower();
                    }
                    else
                    {
                        throw new ConfigurationException("The 'cacheName' attribute in outputCacheSettings section cannot be null or empty string");
                    }

                    string[] boolValStrings = { "enableClientCacheSync", "exceptionsEnabled",
                                                "enableLogs",            "enableDetailLogs" };
                    string   configVal = null;
                    bool     value     = false;

                    for (int i = 0; i < boolValStrings.Length; i++)
                    {
                        if (outputCache.Attributes[boolValStrings[i]] != null)
                        {
                            configVal = outputCache.Attributes[boolValStrings[i]].Value;
                            if (configVal != "true" && configVal != "false")
                            {
                                throw new ConfigurationException("The '" + boolValStrings[i] + "' attribute must be one of the following values: true, false.");
                            }
                            else
                            {
                                value = Convert.ToBoolean(configVal);
                                switch (i)
                                {
                                case 0: outputCacheSettings.ExceptionsEnabled = value; break;

                                case 1: outputCacheSettings.EnableLogs = value; break;

                                case 2: outputCacheSettings.EnableDetailedLogs = value; break;
                                }
                            }
                        }
                    }
                }
            }

            return(outputCacheSettings);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize cache(s) according to settings
        /// </summary>
        /// <param name="settings">output cache settings specified in web.config</param>
        private CacheContainer(OutputCacheSettings settings)
        {
            this._cache = Caching.NCache.InitializeCache(settings.CacheName);

            if (this._cache != null)
            {
                this._cache.ExceptionsEnabled = true;
            }
            if (this._noSyncLocalCache != null)
            {
                this._noSyncLocalCache.ExceptionsEnabled = true;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="application">An <see cref="System.Web.HttpApplication"/> object that provides
        /// references to the intrinsic server objects (for example,
        /// Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        void IHttpModule.Init(HttpApplication application)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            this._onResolveRequestCache = new EventHandler(ResolveRequestCache);
            this._onUpdaterequestCache  = new EventHandler(UpdateRequestCache);
            this._onDispose             = new EventHandler(Dispose);

            application.ResolveRequestCache += this._onResolveRequestCache;
            application.UpdateRequestCache  += this._onUpdaterequestCache;
            application.Disposed            += this._onDispose;

            if (_reader == null)
            {
                lock (s_mutex)
                {
                    if (_reader == null)
                    {
                        NItem.RegisterTypeWithCompactFramework();
                        _reader   = new OutPutCacheConfigReader();
                        _settings = _reader.LoadCacheSettings();
                        _reader.LoadPageSettings();
                    }
                }
            }

            try
            {
                if (IsNullOrEmpty(_settings.CacheName))
                {
                    return;
                }

                if (_settings.EnableLogs || _settings.EnableDetailedLogs)
                {
                    _ncacheLog = new NCacheLogger();
                    _ncacheLog.Initialize(LoggerNames.OutputCache, _settings.CacheName);

                    if (_settings.EnableDetailedLogs)
                    {
                        NCacheLog.SetLevel("all");
                    }
                    else
                    {
                        if (_settings.EnableLogs)
                        {
                            NCacheLog.SetLevel("info");
                        }
                    }
                }

                lock (s_mutex)
                {
                    this._cache = CacheContainer.GetCacheInstance(_settings);
                }

                if (NCacheLog != null)
                {
                    NCacheLog.Info("NOutputCache initialized");
                }
            }
            catch (Exception e)
            {
                RaiseException(e);
            }
        }