What is the difference HttpContext.Current.Cache and ApplicationContext.ApplicationCache.RuntimeCache in Umbraco? And which one is better to use in terms of efficiency?
I used Umbraco 7.4.x in my project and ASP.NET MVC . In my project, I have a list of products that can contain so many elements, and I want to use the cache for this reason. In particular, I want to put my data in the cache and when a new item is added to the Products node, the cache is automatically updated. How to implement it?
Changed: Please give me information about the details of my code.
Products.cshtml:
@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>*@ }
ProductsController.cs:
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); } } }
BaseRenderMvcController.cs:
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; } } }
BaseRenderModel.cs:
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) { } }
performance caching asp.net-mvc umbraco umbraco7
Jahan
source share