/// <summary> /// 首页 /// </summary> public void Index(string lang) { //if (!String.IsNullOrEmpty(Settings.SYS_VIRTHPATH)) //{ // throw new NotSupportedException("不支持虚拟路径运行,请在后台管理中取消!"); //} string html = String.Empty; if (Settings.Opti_IndexCacheSeconds > 0) { ICmsCache cache = Cms.Cache; object obj = cache.Get("cms_index_page_" + lang); if (obj == null) { html = cmsPage.GetIndex(lang); cache.Insert("cms_index_page_" + lang, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds)); } else { html = obj as string; } } else { html = cmsPage.GetIndex(lang); } //response.AddHeader("Cache-Control", "max-age=" + maxAge.ToString()); base.Render(html); }
/// <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); }
/// <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); }
/// <summary> /// 呈现首页 /// </summary> /// <param name="context"></param> public static void RenderIndex(CmsContext context) { try { var site = context.CurrentSite; var siteId = site.SiteId; var cacheId = $"cms_s{siteId}_{(int) Cms.Context.DeviceType}_index_page"; ICmsPageGenerator cmsPage = new PageGeneratorObject(context); if (context.HttpContext.Request.Query("cache") == "0") { Cms.Cache.Rebuilt(); } string html; if (Settings.Opti_IndexCacheSeconds > 0) { ICmsCache cache = Cms.Cache; var obj = cache.Get(cacheId); if (obj == null) { html = cmsPage.GetIndex(); cache.Insert(cacheId, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds)); } else { html = obj as string; } } else { html = cmsPage.GetIndex(); } context.HttpContext.Response.WriteAsync(html); } catch (TemplateException ex) { RenderError(context, ex, false); } }
private static string cacheSha1ETag; //客户端ETag internal CmsCache(ICmsCache cache) { dependCache = cache; this.Reset(null); }
private static string _cacheSha1ETag; //客户端ETag internal CmsCache(ICmsCache cache) { _dependCache = cache; Reset(null); }
/// <summary> /// 设置缓存 /// </summary> /// <param name="cache">缓存包装器</param> public static void Configure(IMemoryCacheWrapper cache) { cacheInstance = new CmsDependCache(cache); }
/// <summary> /// 呈现首页 /// </summary> /// <param name="context"></param> public static void RenderIndex(CmsContext context) { //检测网站状态 if (!context.CheckSiteState()) { return; } //检查缓存 if (!context.CheckAndSetClientCache()) { return; } SiteDto site = context.CurrentSite; //跳转 if (!String.IsNullOrEmpty(site.Location)) { //string url; //if (Regex.IsMatch(archive.Location, "^http://", RegexOptions.IgnoreCase)) //{ // url = archive.Location; //} //else //{ // if (archive.Location.StartsWith("/")) throw new Exception("URL不能以\"/\"开头!"); // url = String.Concat(context.SiteDomain, site.Location); //} context.Response.Redirect(site.Location, true); //302 return; } 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 = String.Empty; 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); }