Sitecore HTML缓存和外部数据源

编程入门 行业动态 更新时间:2024-10-24 10:22:32
本文介绍了Sitecore HTML缓存和外部数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

下面是示例:

  • 更新内容后,单击在Sitecore中发布。
  • 发布后,HTML缓存会自动清除。
  • 呈现子布局,并在第一次请求时将其放入缓存,但是搜索索引尚未更新。
  • 搜索索引已更新。
  • 在下一次缓存清除之前,子布局将显示缓存(过时)日期。
  • After updating content you click "Publish" in Sitecore.
  • HTML cache is automatically cleared after publishing.
  • Sublayout is rendered and put into the cache on first request, but the search index is not yet updated.
  • Search index is updated.
  • 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缓存和外部数据源

    本文发布于:2023-08-05 21:33:31,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1308180.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:数据源   缓存   Sitecore   HTML

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!