What is different between HttpContext.Current.Cache
and ApplicationContext.ApplicationCache.RuntimeCache
in Umbraco?
And which one is better to use in terms of efficiency?
I've used Umbraco 7.4.x
in my project and ASP.NET MVC
. In my project I have a list of products that can be contain so many items and I want to use the cache for this reason.
Specifically I want to put my data in cache and when a new item added to Products
node, the cache automatically be update.
How can I implement it?
Modified: Please give me an implementation with details for 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)
{
}
}