定制sublayout缓存在Sitecore的 [英] Customizing sublayout caching in Sitecore

查看:284
本文介绍了定制sublayout缓存在Sitecore的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在Sitecore的使用器WebControls,有一种方法可以自定义缓存行为 - 重写 GetCachingID 方式。
有没有办法实现这样的事情与Sublayouts(用户控件)?我想添加自定义VaryBy选项(例如 - 改变由月球位置)。

When using WebControls in Sitecore, there is a way to customize caching behavior - override GetCachingID method. Is there a way to achieve something like this with Sublayouts(UserControls)? I'd like to add custom "VaryBy" options(example - "Vary By Moon Position").

推荐答案

是的,sublayout缓存可以通过默认的几个不同的标准有所不同。您可以通过利用不同的参数来做到这一点。的变化,由公司分别是:

Yes, sublayout caching can vary by several different criteria by default. You can leverage varying by parameters to do this. The vary-by's are:


  • 将数据的区别

  • 因设备而异

  • 将登录因人而异

  • 将参数变化

  • 将查询字符串因人而异

  • 将因用户而异

为您在此处自定义由参数变化和您定义的参数是什么的方法。您可以在presentation细节做到这一点,你一个动态分配sublayout到项目(有一个在控件属性底部的部分定义参数),也可以通过C#code设置此。这里使用C#code到A sublayout静态分配到我的布局为例:

The approach for you to customize here is Vary by Parameters and YOU define what the parameters are. You can do this in Presentation Details where you dynamically assign a sublayout to an item (there is a section at the bottom of the control properties to define parameters) or you can set this via C# code. Here an example using C# code to statically assign a sublayout into my layout:

<h1>My website</h1>
<h2>My site is great</h2>
<sc:Sublayout ID="slMyControl" path="~/path/to/my/control.ascx" VaryByParm="true" Cachable="true" runat="server" />

(一件事上面code要注意,为的VaryByParam属性实际上是 VaryByParm 在Sitecore的,这显然是他们的code错字。)

(One thing to note in the above code, the attribute for VaryByParam is actually VaryByParm in Sitecore, which is obviously a typo in their code.)

现在在C#,编程设置参数:

Now in the C#, set the parameters programatically:

slMyControl.Parameters = "myKey1=MyVal1&myKey2=myVal2";

如果你可以在C#中的月亮位置,然后将其转换为字符串,并将其分配给参数:

If you can get a Moon Position in C#, then convert it to a string and assign it to the parameters:

slMyControl.Parameters = "position=" + getMoonPosition().ToString();

我最近缓存由月和年中出现的查询字符串的日历。没有错误处理简单的例子:

I recently cached a calendar by the month and year which appear in the query string. Simple example with no error handling:

slEventCalendar.Parameters = string.Format("m={0}&y={1}", Request.QueryString["m"], Request.QueryString["y"]);

你最终的参数字符串最终成为实际的缓存键的一部分。这个耦合与其它由只是让更多的标准,从而更缓存的实例更复杂的缓存键选择不同而不同。一般的规则是,你所需要的,这将导致从该缓存实例使用的最大量为标准量最少的高速缓存。

The parameter string you end up with eventually becomes part of the actual cache key. Coupling this with other vary by options just making a more complex cache key with more criteria and thus more cached instances. The general rule is, cache by the least amount of criteria you need to which will result in the most amount of use from that cached instance.

这篇关于定制sublayout缓存在Sitecore的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆