禁用Sitecore的一个项目的Html缓存

时间:2011-06-07 10:13:29

标签: sitecore sitecore6

我想禁用1个项目的html缓存,因此它总是呈现。

背景

我需要显示存储在单独数据库中的公司的信息。在sitecore中我有1个项目,其中包含显示所需信息的用户控件,并根据Context参数确定要显示的公司。

sitecore树看起来像这样:

/sitecore
  /content
    /home
      /company-information

网址为:/show-company-information/[company-name]-[company-id]。我有一个管道模块,用于解析URL并将公司信息设置为当前项目,并将公司ID添加到HttpContext.Current.Items。这就是我的用户控制如何计算要呈现的公司信息。

这一切在开发中都可以正常工作,但是一旦将其部署到Content Delivery服务器,它就会停止正常工作。第一次访问页面时,它会被缓存,每个连续的请求都会返回第一次缓存的公司信息。

我目前的解决方法是在解析公司信息的同一管道步骤中清除company-info项的HTML缓存,但这似乎是一个非常糟糕的解决方案。

有更好的方法可以达到相同的效果吗?


修改

以下是在web.config中设置网站的方式以及网络数据库配置:

<site name="website" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content/Home/" startItem="/home" language="en-GB" database="web" domain="extranet" loginPage="/user-login.aspx" allowDebug="true" cacheHtml="true" htmlCacheSize="400MB" registryCacheSize="500KB" viewStateCacheSize="500KB" xslCacheSize="20MB" filteredItemsCacheSize="20MB" enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" />

<!-- CACHE SIZES -->
    <cacheSizes>
      <sites>
        <website>
          <html>500MB</html>
          <registry>500KB</registry>
          <viewState>500KB</viewState>
          <xsl>200MB</xsl>
        </website>
      </sites>
    </cacheSizes>

<database id="web" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
    <param desc="name">$(id)</param>
    <icon>Network/16x16/earth.png</icon>
    <securityEnabled>true</securityEnabled>
    <dataProviders hint="list:AddDataProvider">
      <dataProvider ref="dataProviders/main" param1="$(id)">
        <disableGroup>publishing</disableGroup>
        <prefetch hint="raw:AddPrefetch">
          <sc.include file="/App_Config/Prefetch/Common.config" />
          <sc.include file="/App_Config/Prefetch/Web.config" />
        </prefetch>
      </dataProvider>
    </dataProviders>
    <indexes hint="list:AddIndex">
      <index path="indexes/index[@id='articleIndex']" />
    </indexes>
    <proxiesEnabled>false</proxiesEnabled>
    <proxyDataProvider ref="proxyDataProviders/main" param1="$(id)" />
    <archives hint="raw:AddArchive">
      <archive name="archive" />
      <archive name="recyclebin" />
    </archives>
    <Engines.HistoryEngine.Storage>
      <obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
        <param connectionStringName="$(id)" />
        <EntryLifeTime>30.00:00:00</EntryLifeTime>
      </obj>
    </Engines.HistoryEngine.Storage>
    <cacheSizes hint="setting">
      <data>400MB</data>
      <items>400MB</items>
      <paths>10MB</paths>
      <standardValues>1MB</standardValues>
    </cacheSizes>
  </database>
</databases>

页面布局结构:

layout - no output caching
  - sublayout - no caching options ticked
    - offending sublayout - no caching options ticked

我们是否做了任何错误的事情,以便如此积极地缓存?

4 个答案:

答案 0 :(得分:2)

您可以使用CacheManager在Page Load事件期间关闭缓存,然后在PreRender中重新打开它。这将确保页面的html / xslt控件不会被缓存。

在检索HTML缓存时,CacheManager类具有以下所有控件使用的方法

/// <summary>
/// Gets the HTML cache.
/// </summary>
/// <param name="site">The site.</param>
/// <returns>The HTML cache.</returns>
public static HtmlCache GetHtmlCache(SiteContext site)
{
  if (_enabled && (site != null))
  {
    return site.Caches.HtmlCache;
  }
  return null;
}

因此,将Enabled Property设置为false将停止从缓存中呈现的控件:

CacheManager.Enabled = false;

它很残酷,但它有效。

答案 1 :(得分:1)

如果您的HTML正在缓存,则来自特定的呈现,例如特定的子布局。如果您将子布局设置为缓存并在布局详细信息中有所不同,请撤消该布局。或者,您可能在代码中执行此操作,在这种情况下,您可以将C#更改为不缓存它。

这是设置为缓存的代码中的子布局,您可能有类似的东西,您不想缓存:

<sc:Sublayout Path="~/layouts/sublayouts/mycontrol.ascx" Cacheable="true" runat="server" />

答案 2 :(得分:0)

如果仅通过发布任何sitecore项来清除此缓存问题,则可以安全地假设其为sitecore HTML缓存。

启用了缓存的任何布局或子布局也会缓存输出中添加的任何控件。因此,如果此控件或渲染的任何父子布局启用了缓存,则需要禁用它。

查看页面缓存设置的简便方法是通过调试器[开始]&gt; [调试] 将鼠标悬停在控件上可以查看其生成的缓存设置。

答案 3 :(得分:0)

如果您的项目是子布局,则可以在页面编辑器组件属性中或通过“缓存”部分中的子布局项的定义禁用其渲染缓存。

例如,我有一个禁用缓存的搜索结果子布局。