Пример #1
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            SiteDto site    = context.CurrentSite;
            int     siteId  = site.SiteId;
            string  cacheId = String.Concat("cms_s", siteId.ToString(), "_index_page");

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            if (context.Request["cache"] == "0")
            {
                Cms.Cache.Rebuilt();
            }


            string html;

            if (Settings.Opti_IndexCacheSeconds > 0)
            {
                ICmsCache cache = Cms.Cache;
                object    obj   = cache.Get(cacheId);
                if (obj == null)
                {
                    html = cmsPage.GetIndex(null);
                    cache.Insert(cacheId, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds));
                }
                else
                {
                    html = obj as string;
                }
            }
            else
            {
                //DateTime dt = DateTime.Now;
                html = cmsPage.GetIndex(null);
                //context.Render("<br />"+(DateTime.Now - dt).TotalMilliseconds.ToString() + "<br />");
            }

            //response.AddHeader("Cache-Control", "max-age=" + maxAge.ToString());
            context.Render(html);
        }
Пример #2
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }
            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            SiteDto           site    = context.CurrentSite;
            int               siteId  = site.SiteId;
            string            cacheId = String.Format("cms_s{0}_{1}_index_page", siteId, (int)Cms.Context.DeviceType);
            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            if (context.Request["cache"] == "0")
            {
                Cms.Cache.Rebuilt();
            }
            string html;

            if (Settings.Opti_IndexCacheSeconds > 0)
            {
                ICmsCache cache = Cms.Cache;
                object    obj   = cache.Get(cacheId);
                if (obj == null)
                {
                    html = cmsPage.GetIndex(null);
                    cache.Insert(cacheId, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds));
                }
                else
                {
                    html = obj as string;
                }
            }
            else
            {
                html = cmsPage.GetIndex(null);
            }
            context.Render(html);
        }