asp.net-mvc – 哪种类型的缓存适合在Umbraco项目中使用,如何实
HttpContext.Current.Cache和ApplicationContext.ApplicationCache.RuntimeCachein Umbraco有什么不同?
哪一个在效率方面更好用? 我在我的项目和ASP.NET MVC中使用了Umbraco 7.4.x.在我的项目中,我有一个产品列表,可以包含这么多项目,因此我想使用缓存. 改性:
@using Jahan.Handicraft.Model.UModel.URenderModel @using Jahan.Handicraft.Model.UModel @inherits Umbraco.Web.Mvc.UmbracoViewPage<BaseRenderModel<Jahan.Handicraft.Model.UModel.Products>> @foreach (var prod in Model.Model.ProductList.Skip((page - 1) * pageSize).Take(pageSize)) { @*<div>LOAD DATA</div>*@ }
namespace Jahan.Handicraft.Web.Mvc.UmbracoCms.App.Controllers { public class ProductsController : BaseRenderMvcController<Products> { // GET: Products public override ActionResult Index(RenderModel model) { return base.Index(Instance); } } }
public class BaseRenderMvcController<TBaseEntity> : RenderMvcController where TBaseEntity : BaseEntity { private BaseRenderModel<TBaseEntity> _instance; public BaseRenderModel<TBaseEntity> Instance { get { if (_instance == null) { _instance = new BaseRenderModel<TBaseEntity>(CurrentContent,CurrentCultureInfo); } return _instance; } set { } } public virtual IPublishedContent CurrentContent { get { if (UmbracoContext.Current != null) return UmbracoContext.Current.PublishedContentRequest.PublishedContent; return null; } } public virtual CultureInfo CurrentCultureInfo { get { if (UmbracoContext.Current != null) return UmbracoContext.Current.PublishedContentRequest.PublishedContent.GetCulture(); return null; } } }
public class BaseRenderModel<TBaseEntity> : RenderModel where TBaseEntity : BaseEntity { public TBaseEntity Model { get; set; } public BaseRenderModel(IPublishedContent content,CultureInfo culture) : base(content,culture) { object[] args = new object[] { content,culture }; Model = (TBaseEntity)Activator.CreateInstance(typeof(TBaseEntity),args); } public BaseRenderModel(IPublishedContent content) : base(content) { object args = new object[] { content }; Model = (TBaseEntity)Activator.CreateInstance(typeof(TBaseEntity),args); } public BaseRenderModel() : base(UmbracoContext.Current.PublishedContentRequest.PublishedContent) { } } 解决方法
您可以在Umbraco中使用多个缓存.您有以下服务:
ApplicationContext.ApplicationCache.RuntimeCache – 这是一个可供所有请求使用的缓存. ApplicationContext.ApplicationCache.RequestCache – 这是一个仅为当前请求持续的缓存.如果要缓存对象以便在多个视图中使用,请使用. ApplicationContext.ApplicationCache.StaticCache – 这是一个静态缓存,应该很少使用并谨慎使用,因为不正确的使用会导致内存问题. 如果在后台更改节点时需要更新要缓存的项目,则需要编写ICacheRefresher来处理它. 以下是三个缓存的一些信息,以及如何将项目放入缓存:https://our.umbraco.org/documentation/reference/cache/updating-cache 这里有一个ICacheRefresher的例子:https://github.com/Jeavon/SEOCheckerCacheRefresher (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – Orchard CMS 1.x [文档存储] – 混合记录支持和
- ASP.NET httpRedirect:重定向所有页面,除了一个
- asp.net-mvc – 从控制器的操作调用集线器方法
- 开发自己的Data Access Application Block[上篇]
- asp.net-mvc – 快捷键在Visual Studio 2012中不起作用
- asp.net-mvc – 如何在ASP.NET控制器中获取“MvcApplicatio
- asp.net – .NET Signalr MapConnection已经过时了?
- asp.net-mvc-2 – 如何通过ASP.NET MVC 2.0中的textarea接受
- asp.net-mvc – ActionExecutingContext – ActionParamete
- asp.net – Telerik UI控件与jQuery的客户端UI
- ASP.NET中的网站或Web应用程序
- 获取一些401 – 访问我的ASP.NET MVC网站时未经授
- 给 EF Core 查询增加 With NoLock
- asp.net-mvc – Json返回时如何读取modelstate错
- asp.net-mvc – ASP.NET MVC中的CSS/JS文件的自动
- asp.net-mvc-3 – 如何在代码中检测属性是否使用
- asp.net – 如果在MVC 3中没有认证,如何轻松重定
- asp.net-mvc – ASP.NET MVC是否允许私有ViewMod
- 没有更新过期的ASP.NET Cookie更新值?
- asp.net-mvc-3 – MVC3 Webgrid Paging在Jquery对