HTML缓存和外部数据源

HTML缓存和外部数据源

本文介绍了Sitecore HTML缓存和外部数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您要缓存一些依赖于外部数据(搜索索引等)的子布局时,您将如何处理?

How would you handle a situation when you want to cache some sublayout that relies on external data(search index, etc.)?

下面是示例:


  1. 更新内容后,单击
    在Sitecore中发布。

  2. 发布
    后,HTML缓存会自动清除。

  3. 呈现子布局,并在
    第一次请求时将其放入缓存,但是搜索索引
    尚未更新。

  4. 搜索索引已更新。

  5. 在下一次缓存清除之前,子布局将显示缓存(过时)日期。

  1. After updating content you click"Publish" in Sitecore.
  2. HTML cache is automatically cleared afterpublishing.
  3. Sublayout is rendered and put into the cache onfirst request, but the search indexis not yet updated.
  4. Search index is updated.
  5. Until the next cache cleanup, sublayout will display the cached (obsolete) date.

有没有简单的方法可以解决此问题?

Are there any simple ways to fix this issue?

到目前为止,我只有一个主意-在索引更新结束时触发缓存清理,但是由于许多原因它可能很复杂。

I've got only one idea so far - trigger cache cleanup when the index update is over, but it might be complicated for many reasons.

推荐答案

您可以缓存子布局并因参数而异,您可以在其中定义自定义参数。这些参数可以是Lucene的唯一字符串,例如上次对其进行重建。

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.

例如,

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

注意:Sitecore代码有错字,而 VaryByParm不是 VaryByParam

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

在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.

这篇关于Sitecore HTML缓存和外部数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:09