Пример #1
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);
         }
     }
 }
Пример #2
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);
        }