उम्ब्राको में HttpContext.Current.Cache
और ApplicationContext.ApplicationCache.RuntimeCache
के बीच क्या अंतर है? और दक्षता के मामले में कौन सा उपयोग करना बेहतर है?किस प्रकार का कैश उम्ब्राको प्रोजेक्ट में उपयोग करने के लिए उपयुक्त है और मैं एक बुद्धिमान कैश को कैसे कार्यान्वित कर सकता हूं?
मैंने अपनी परियोजना में Umbraco 7.4.x
और ASP.NET MVC
का उपयोग किया है। मेरी परियोजना में मेरे पास उत्पादों की एक सूची है जिसमें बहुत से आइटम हो सकते हैं और मैं इस कारण से कैश का उपयोग करना चाहता हूं। विशेष रूप से मैं अपना डेटा कैश में रखना चाहता हूं और जब कोई नया आइटम Products
नोड में जोड़ा जाता है, तो कैश स्वचालित रूप से अपडेट हो जाता है। मैं इसे कैसे कार्यान्वित कर सकता हूं?
संशोधित: कृपया मुझे मेरे कोड के विवरण के साथ कार्यान्वयन दें।
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)
{
}
}