private void BindModuleCacheProviderList()
 {
     cboModuleCacheProvider.DataSource = GetFilteredProviders(ModuleCachingProvider.GetProviderList(), "ModuleCachingProvider");
     cboModuleCacheProvider.DataBind();
     if (cboModuleCacheProvider.Items.Count > 0)
     {
         var    defaultModuleCache = ComponentFactory.GetComponent <ModuleCachingProvider>();
         string providerKey        = (from provider in ModuleCachingProvider.GetProviderList() where provider.Value.Equals(defaultModuleCache) select provider.Key).SingleOrDefault();
         if (!string.IsNullOrEmpty(Entities.Host.Host.ModuleCachingMethod))
         {
             if (cboModuleCacheProvider.FindItemByValue(Entities.Host.Host.ModuleCachingMethod) != null)
             {
                 cboModuleCacheProvider.FindItemByValue(Entities.Host.Host.ModuleCachingMethod).Selected = true;
             }
             else
             {
                 cboModuleCacheProvider.FindItemByValue(providerKey).Selected = true;
             }
         }
         else
         {
             cboModuleCacheProvider.FindItemByValue(providerKey).Selected = true;
         }
     }
 }
Example #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Trys to load previously cached Module Content
        /// </summary>
        /// <returns>A Boolean that indicates whether the cahed content was loaded</returns>
        private bool TryLoadCached()
        {
            bool   success       = false;
            string cachedContent = string.Empty;

            try
            {
                var cache  = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod());
                var varyBy = new SortedDictionary <string, string> {
                    { "locale", Thread.CurrentThread.CurrentUICulture.ToString() }
                };

                string cacheKey    = cache.GenerateCacheKey(_moduleConfiguration.TabModuleID, varyBy);
                byte[] cachedBytes = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod()).GetModule(_moduleConfiguration.TabModuleID, cacheKey);

                if (cachedBytes != null && cachedBytes.Length > 0)
                {
                    cachedContent = Encoding.UTF8.GetString(cachedBytes);
                    success       = true;
                }
            }
            catch (Exception ex)
            {
                cachedContent = string.Empty;
                Exceptions.LogException(ex);
                success = false;
            }
            if (success)
            {
                this.RestoreCachedClientResourceRegistrations(cachedContent);
                _control = _moduleControlPipeline.CreateCachedControl(cachedContent, _moduleConfiguration);
                Controls.Add(_control);
            }
            return(success);
        }
Example #3
0
 protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
 {
     if (_IsCached)
     {
         base.RenderContents(writer);
     }
     else
     {
         if (SupportsCaching() && IsViewMode() && !Common.Globals.IsAdminControl())
         {
             string       _cachedOutput = Null.NullString;
             StringWriter tempWriter    = new StringWriter();
             _Control.RenderControl(new HtmlTextWriter(tempWriter));
             _cachedOutput = tempWriter.ToString();
             if (!string.IsNullOrEmpty(_cachedOutput) && (!HttpContext.Current.Request.Browser.Crawler))
             {
                 byte[] moduleContent        = System.Text.Encoding.UTF8.GetBytes(_cachedOutput);
                 ModuleCachingProvider cache = ModuleCachingProvider.Instance(_ModuleConfiguration.GetEffectiveCacheMethod());
                 System.Collections.Generic.SortedDictionary <string, string> varyBy = new System.Collections.Generic.SortedDictionary <string, string>();
                 varyBy.Add("locale", System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
                 string cacheKey = cache.GenerateCacheKey(_ModuleConfiguration.TabModuleID, varyBy);
                 cache.SetModule(_ModuleConfiguration.TabModuleID, cacheKey, new TimeSpan(0, 0, _ModuleConfiguration.CacheTime), moduleContent);
             }
             writer.Write(_cachedOutput);
         }
         else
         {
             base.RenderContents(writer);
         }
     }
 }
        /// <summary>
        /// Synchronizes the cache.
        /// </summary>
        /// <remarks>
        /// Based on DNN SynchronizeModule(int moduleID)
        /// </remarks>
        private static void SynchronizeViewModule(ModuleInfo module)
        {
            DataProvider dataProvider = DataProvider.Instance();
            //IList<ModuleInfo> modules = ModuleController.Instance.GetTabModulesByModule(moduleId);

            Hashtable tabSettings = TabController.Instance.GetTabSettings(module.TabID);

            if (tabSettings["CacheProvider"] != null && tabSettings["CacheProvider"].ToString().Length > 0)
            {
                var outputProvider = OutputCachingProvider.Instance(tabSettings["CacheProvider"].ToString());
                outputProvider?.Remove(module.TabID);
            }

            if (module.CacheTime > 0)
            {
                var cachingProvider = ModuleCachingProvider.Instance(module.GetEffectiveCacheMethod());
                cachingProvider?.Remove(module.TabModuleID);
            }

            //Synchronize module is called when a module needs to indicate that the content
            //has changed and the cache's should be refreshed.  So we can update the Version
            //and also the LastContentModificationDate
            dataProvider.UpdateTabModuleVersion(module.TabModuleID, Guid.NewGuid());
            dataProvider.UpdateModuleLastContentModifiedOnDate(module.ModuleID);

            ////We should also indicate that the Transalation Status has changed
            //if (PortalController.GetPortalSettingAsBoolean("ContentLocalizationEnabled", module.PortalID, false))
            //{
            //    ModuleController.Instance.UpdateTranslationStatus(module, false);
            //}

            // and clear the cache
            ModuleController.Instance.ClearCache(module.TabID);
        }
Example #5
0
        private bool TryLoadCached()
        {
            bool   bSuccess       = false;
            string _cachedContent = string.Empty;

            try
            {
                ModuleCachingProvider cache = ModuleCachingProvider.Instance(_ModuleConfiguration.GetEffectiveCacheMethod());
                System.Collections.Generic.SortedDictionary <string, string> varyBy = new System.Collections.Generic.SortedDictionary <string, string>();
                varyBy.Add("locale", System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
                string cacheKey    = cache.GenerateCacheKey(_ModuleConfiguration.TabModuleID, varyBy);
                byte[] cachedBytes = ModuleCachingProvider.Instance(_ModuleConfiguration.GetEffectiveCacheMethod()).GetModule(_ModuleConfiguration.TabModuleID, cacheKey);
                if (cachedBytes != null && cachedBytes.Length > 0)
                {
                    _cachedContent = System.Text.Encoding.UTF8.GetString(cachedBytes);
                    bSuccess       = true;
                }
            }
            catch (Exception ex)
            {
                _cachedContent = string.Empty;
                bSuccess       = false;
                ex.ToString();
            }
            if (bSuccess)
            {
                _Control = new CachedModuleControl(_cachedContent);
                this.Controls.Add(_Control);
            }
            return(bSuccess);
        }
        public string GetEffectiveCacheMethod()
        {
            string effectiveCacheMethod;

            if (!string.IsNullOrEmpty(this.CacheMethod))
            {
                effectiveCacheMethod = this.CacheMethod;
            }
            else if (!string.IsNullOrEmpty(Host.Host.ModuleCachingMethod))
            {
                effectiveCacheMethod = Host.Host.ModuleCachingMethod;
            }
            else
            {
                var defaultModuleCache = ComponentFactory.GetComponent <ModuleCachingProvider>();
                effectiveCacheMethod = (from provider in ModuleCachingProvider.GetProviderList() where provider.Value.Equals(defaultModuleCache) select provider.Key).SingleOrDefault();
            }

            if (string.IsNullOrEmpty(effectiveCacheMethod))
            {
                throw new InvalidOperationException(Localization.GetString("EXCEPTION_ModuleCacheMissing"));
            }

            return(effectiveCacheMethod);
        }
Example #7
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Trys to load previously cached Module Content
        /// </summary>
        /// <returns>A Boolean that indicates whether the cahed content was loaded</returns>
        /// <history>
        ///     [cnurse]	12/15/2007  created
        /// </history>
        /// -----------------------------------------------------------------------------
        private bool TryLoadCached()
        {
            bool   success       = false;
            string cachedContent = string.Empty;

            try
            {
                var cache  = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod());
                var varyBy = new SortedDictionary <string, string> {
                    { "locale", Thread.CurrentThread.CurrentUICulture.ToString() }
                };

                string cacheKey    = cache.GenerateCacheKey(_moduleConfiguration.TabModuleID, varyBy);
                byte[] cachedBytes = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod()).GetModule(_moduleConfiguration.TabModuleID, cacheKey);

                if (cachedBytes != null && cachedBytes.Length > 0)
                {
                    cachedContent = Encoding.UTF8.GetString(cachedBytes);
                    success       = true;
                }
            }
            catch (Exception ex)
            {
                cachedContent = string.Empty;
                Exceptions.LogException(ex);
                success = false;
            }
            if (success)
            {
                //parse the registered CDF from content
                var matches = Regex.Matches(cachedContent, "<\\!--CDF\\((JAVASCRIPT|CSS)\\|(.+?)\\)-->", RegexOptions.IgnoreCase);
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        cachedContent = cachedContent.Replace(match.Value, string.Empty);
                        if (match.Groups[1].Value.ToUpperInvariant() == "JAVASCRIPT")
                        {
                            ClientResourceManager.RegisterScript(Page, match.Groups[2].Value);
                        }
                        else
                        {
                            ClientResourceManager.RegisterStyleSheet(Page, match.Groups[2].Value);
                        }
                    }
                }
                _control = ModuleControlFactory.CreateCachedControl(cachedContent, _moduleConfiguration);
                Controls.Add(_control);
            }
            return(success);
        }
Example #8
0
        private void BindModuleCacheProviderList()
        {
            cboCacheProvider.DataSource = GetFilteredProviders(ModuleCachingProvider.GetProviderList(), "ModuleCachingProvider");
            cboCacheProvider.DataBind();

            cboCacheProvider.Items.Insert(0, new ListItem(Localization.GetString("None_Specified"), ""));

            if (!string.IsNullOrEmpty(Module.GetEffectiveCacheMethod()) && cboCacheProvider.Items.FindByValue(Module.GetEffectiveCacheMethod()) != null)
            {
                cboCacheProvider.Items.FindByValue(Module.GetEffectiveCacheMethod()).Selected = true;
            }
            else
            {
                //select the None Specified value
                cboCacheProvider.Items[0].Selected = true;
            }

            lblCacheInherited.Visible = Module.CacheMethod != Module.GetEffectiveCacheMethod();
        }
Example #9
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// RenderContents renders the contents of the control to the output stream
        /// </summary>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            if (_isCached)
            {
                //Render the cached control to the output stream
                base.RenderContents(writer);
            }
            else
            {
                if (SupportsCaching() && IsViewMode(_moduleConfiguration, PortalSettings) && !Globals.IsAdminControl() && !IsVersionRequest())
                {
                    //Render to cache
                    var tempWriter = new StringWriter();

                    _control.RenderControl(new HtmlTextWriter(tempWriter));
                    string cachedOutput = tempWriter.ToString();

                    if (!string.IsNullOrEmpty(cachedOutput) && (!HttpContext.Current.Request.Browser.Crawler))
                    {
                        //Save content to cache
                        var moduleContent = Encoding.UTF8.GetBytes(cachedOutput);
                        var cache         = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod());

                        var varyBy = new SortedDictionary <string, string> {
                            { "locale", Thread.CurrentThread.CurrentUICulture.ToString() }
                        };

                        var cacheKey = cache.GenerateCacheKey(_moduleConfiguration.TabModuleID, varyBy);
                        cache.SetModule(_moduleConfiguration.TabModuleID, cacheKey, new TimeSpan(0, 0, _moduleConfiguration.CacheTime), moduleContent);
                    }

                    //Render the cached content to Response
                    writer.Write(cachedOutput);
                }
                else
                {
                    //Render the control to Response
                    base.RenderContents(writer);
                }
            }
        }
Example #10
0
 public IEnumerable <KeyValuePair <string, string> > GetModuleCacheProviders()
 {
     return(GetFilteredProviders(ModuleCachingProvider.GetProviderList(), "ModuleCachingProvider"));
 }