2016-08-31 39 views
8

Umbraco'da HttpContext.Current.Cache ve ApplicationContext.ApplicationCache.RuntimeCache arasındaki farklar nelerdir? Ve hangisi verimlilik açısından kullanmak daha iyidir?Umbraco projesinde kullanmak için hangi tür önbellek kullanılabilir ve akıllı bir önbelleği nasıl uygularım?

Projemde Umbraco 7.4.x ve ASP.NET MVC kullanıyorum. Projemde çok fazla ürün bulunabilecek bir ürün listem var ve bu nedenle önbellek kullanmak istiyorum. Özellikle veriyi önbellekte koymak istiyorum ve Products düğümüne yeni bir öğe eklendiğinde, önbellek otomatik olarak güncellenir. Bunu nasıl uygularım?

Değiştirilmiş: Lütfen kodumun ayrıntılarını içeren bir uygulama belirtin.

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:

Eğer Umbraco içinde kullanabileceğiniz birkaç önbelleklerini vardır
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) 
{ 

} 
} 

cevap

7

. Kullanılabilir şu var:

ApplicationContext.ApplicationCache.RuntimeCache - Bu TÜM isteklerine kullanılabilir bir önbelleğidir.

ApplicationContext.ApplicationCache.RequestCache - Bu, SADECE geçerli istek için geçerli olan bir önbellek. Bir nesneyi çeşitli görünümlerde kullanmak için önbelleğe almak istiyorsanız kullanın.

ApplicationContext.ApplicationCache.StaticCache - Bu statik bir önbellektir ve yanlış kullanım bellek sorunlarına neden olabileceği için çok nadiren ve dikkatle kullanılmalıdır.

Önbelleğe aldığınız öğelerin arka ofiste bir düğüm değiştirildiğinde değiştirilmeleri gerekiyorsa, bunu işlemek için bir ICacheRefresher yazmanız gerekir. https://github.com/Jeavon/SEOCheckerCacheRefresher

: https://our.umbraco.org/documentation/reference/cache/updating-cache

burada ICacheRefresher örneği var: Burada

yaklaşık üç önbelleklerini üzerine bilgi ve nasıl önbelleğine ürün almak için var