Sitecore HTML cache and external data sources

半城伤御伤魂 提交于 2019-12-06 18:49:26

You can cache the sublayout and vary by params, where you define the custom params. Those params can be a unique string from Lucene, e.g the last time it was rebuilt.

E.g.

<sc:sublayout ID="slNews" Path="NewsList.ascx" Cacheable="true" VaryByParm="true" runat="server" />

Note: the Sitecore code has a typo and it's "VaryByParm" not "VaryByParam"

In C#:

string lastIndexRebuild = GetLastRebuildTimeOfIndex().ToString();
slNews.Parameters = "lastIndexRebuild=" + lastIndexRebuild;

If you can somehow define a method to determine when the index was last rebuilt, you can use that as a parameter to define custom cache instances based on when the index freshness or staleness. You can even tack on additional parameters, like a datasource, etc.

John West has recently posted related blog post -

Schedule Expiration for Output Cache Entries with the Sitecore ASP.NET CMS

You can set cache expiration on sublayouts, in most cases it seems to be the easiest solution when your control relies on external datasource.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!