What type of cache is suitable for use in a Umbraco project, and how can I implement smart cache?

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) { } } 
+8
performance caching asp.net-mvc umbraco umbraco7
source share
1 answer

Umbraco can use multiple caches. You have the following:

ApplicationContext.ApplicationCache.RuntimeCache is the cache available for ALL requests.

ApplicationContext.ApplicationCache.RequestCache is a cache that is used only for the current request. Use if you want to cache an object for use in multiple views.

ApplicationContext.ApplicationCache.StaticCache is a static cache and should be used very rarely and with caution, as misuse can cause memory problems.

If the elements that you cache need to be updated when the node is changed in the back office, you will need to write ICacheRefresher to process it.

Here is information about the three caches and how to get items into the cache: https://our.umbraco.org/documentation/reference/cache/updating-cache

Here is an example of ICacheRefresher: https://github.com/Jeavon/SEOCheckerCacheRefresher

+7
source share

All Articles