asp.net-mvc – 哪种类型的缓存适合在Umbraco项目中使用,如何实现智能缓存?
|
HttpContext.Current.Cache和ApplicationContext.ApplicationCache.RuntimeCachein Umbraco有什么不同?
我在我的项目和ASP.NET MVC中使用了Umbraco 7.4.x.在我的项目中,我有一个产品列表,可以包含这么多项目,因此我想使用缓存. 改性:
@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>*@
}
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);
}
}
}
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;
}
}
}
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)
{
}
}
解决方法您可以在Umbraco中使用多个缓存.您有以下服务:ApplicationContext.ApplicationCache.RuntimeCache – 这是一个可供所有请求使用的缓存. ApplicationContext.ApplicationCache.RequestCache – 这是一个仅为当前请求持续的缓存.如果要缓存对象以便在多个视图中使用,请使用. ApplicationContext.ApplicationCache.StaticCache – 这是一个静态缓存,应该很少使用并谨慎使用,因为不正确的使用会导致内存问题. 如果在后台更改节点时需要更新要缓存的项目,则需要编写ICacheRefresher来处理它. 以下是三个缓存的一些信息,以及如何将项目放入缓存:https://our.umbraco.org/documentation/reference/cache/updating-cache 这里有一个ICacheRefresher的例子:https://github.com/Jeavon/SEOCheckerCacheRefresher (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – OWIN AuthorizeEndpoint,其redirect_uri不同于w
- asp.net – 如何使用在web.config文件
- asp.net – Service Fabric中的.NET Core RC2
- 资源解释为样式表,但在ASP.NET IIS中使用MIME类型的文本/ h
- asp.net-mvc – SignalR和MVC包
- asp.net – UpdatePanel中的动态创建控件?
- asp.net-mvc – 如何为MVC4配置Ninject并提供自定义成员资格
- 错误处理 – 是否可以在ASP Classic中的try-catch像错误处理
- asp.net-mvc – MVC 5 Owin Facebook Auth导致空参考异常
- asp.net-mvc – 我应该选择云吗?
- asp.net-core – 使用AspNet Core 2.0进行Google
- asp.net-mvc-3 – 对复选框不起作用的MVC不显眼的
- asp.net-mvc – ASP.NET MVC ModelMetaData:有没
- 在asp.net中使用SQL查询中的变量(C#)
- ASP.NET MVC – 如何从局部视图中获取当前操作?
- asp.net-mvc – ASP.NET MVC,图层,模型,存储库等
- ASP.NET Razor查看Html.TextBox大小/宽度
- asp.net-mvc – 在MVC Razor中,如何在子布局下面
- asp.net – RequiredFieldValidator在文本上放置
- 在asp.net中排序gridview的列c#
