sitecore RSS 缓存

发布于 2024-12-09 19:27:55 字数 2685 浏览 0 评论 0原文

我一直致力于在 sitecore 6.4 中实现自定义 RSS feed。我的自定义行为非常有限,我实际上想要的只是添加作者的链接(我们的作者字段是参考字段,因此我们不能使用内置的作者归属)。

我重写了 PublicFeed 类上的 RenderItem() ,以便我可以利用我自己的 FeedRenderer 类实现(其中作者逻辑是安置)。我的方法遵循这个John West 概述的模式 用于添加您自己的渲染行为:

public class MyPUblicFeed: PublicFeed
{

    protected override SyndicationItem RenderItem(Item item)
    {
        Assert.ArgumentNotNull(item, "item");
        Control rendererControl = FeedUtil.GetFeedRendering(item);

        if (rendererControl == null)
        {
            return null;
        }

        using (new ContextItemSwitcher(item))
        {
            var myRenderer= rendererControl as MyFeedRenderer;
            if (myRenderer!= null)
            {
                myRenderer.Database = SitecoreHelper.CurrentDatabase.Name;
                return myRenderer.RenderItem();
            }

            var renderer = rendererControl as Sitecore.Web.UI.WebControls.FeedRenderer;
            if (renderer != null)
            {
                renderer.Database = SitecoreHelper.CurrentDatabase.Name;
                return renderer.RenderItem();
            }
        }

        throw new InvalidOperationException("FeedRenderer rendering must be of Sitecore.Web.UI.WebControls.FeedRenderer type");
    }

}

现在我的渲染类:

public class MyFeedRenderer: Sitecore.Web.UI.WebControls.FeedRenderer
{

    public override SyndicationItem RenderItem()
    {
        Item item = base.GetItem();
        var syndicationItem = base.RenderItem();

        //unfortunately we have to parse params again :(
        FeedRenderingParameters feedRenderingParameter = FeedRenderingParameters.Parse(base.Parameters);

        AddAuthor(syndicationItem, item, feedRenderingParameter);

        return syndicationItem;
    }


    private static void AddAuthor(SyndicationItem syndicationItem, Item item, FeedRenderingParameters feedRenderingParameter)
    {
        //clear out authors added by base class
        syndicationItem.Authors.Clear();

        //logic for adding author here
    }
}

这一切都很好,输出正是我想要的,但缓存元素似乎不起作用。我已在实际项目本身上设置了可缓存标志,时间跨度为01:00:00。这似乎不起作用 - 如果我在上述任一类中放置断点,则每次请求提要时都会命中该断点。

所以然后我尝试在控制级别启用缓存,使用 VaryByData 打开缓存以进行 MyFeedRenderer 渲染。唉,这也不起作用,每次都会命中断点。

有人可以就此事提供任何建议吗?该文档只是建议在实际的提要项目上打开它,而不是在渲染级别,但这似乎都不适合我。有趣的是,HTML 缓存在其他地方起作用 - RSS 是否也放入 HTML 缓存中?

提前致谢, 缺口

I have been working on implementing a custom RSS feed in sitecore 6.4. My custom behaviour is very limited, all i effectively wanted to is add a link for author (our author field is a reference field so we cannot use the built in author attribution).

I overrode RenderItem() on the PublicFeed class so that i could make use of my own implementation of the FeedRenderer class (where the author logic is housed). my approach follows this pattern outlined by John West for adding your own rendering behaviour:

public class MyPUblicFeed: PublicFeed
{

    protected override SyndicationItem RenderItem(Item item)
    {
        Assert.ArgumentNotNull(item, "item");
        Control rendererControl = FeedUtil.GetFeedRendering(item);

        if (rendererControl == null)
        {
            return null;
        }

        using (new ContextItemSwitcher(item))
        {
            var myRenderer= rendererControl as MyFeedRenderer;
            if (myRenderer!= null)
            {
                myRenderer.Database = SitecoreHelper.CurrentDatabase.Name;
                return myRenderer.RenderItem();
            }

            var renderer = rendererControl as Sitecore.Web.UI.WebControls.FeedRenderer;
            if (renderer != null)
            {
                renderer.Database = SitecoreHelper.CurrentDatabase.Name;
                return renderer.RenderItem();
            }
        }

        throw new InvalidOperationException("FeedRenderer rendering must be of Sitecore.Web.UI.WebControls.FeedRenderer type");
    }

}

And now for my rendering class:

public class MyFeedRenderer: Sitecore.Web.UI.WebControls.FeedRenderer
{

    public override SyndicationItem RenderItem()
    {
        Item item = base.GetItem();
        var syndicationItem = base.RenderItem();

        //unfortunately we have to parse params again :(
        FeedRenderingParameters feedRenderingParameter = FeedRenderingParameters.Parse(base.Parameters);

        AddAuthor(syndicationItem, item, feedRenderingParameter);

        return syndicationItem;
    }


    private static void AddAuthor(SyndicationItem syndicationItem, Item item, FeedRenderingParameters feedRenderingParameter)
    {
        //clear out authors added by base class
        syndicationItem.Authors.Clear();

        //logic for adding author here
    }
}

this all works great, outputting exactly what i want, but the caching element doesn't appear to be working. I have set the cacheable flag on the actual item itself with a timespan of 01:00:00. This didn't appear to work - if i put a breakpoint in either of the above classes it is hit everytime the feed is requested.

so then i tried to enable caching at a control level, turning caching on with VaryByData for the MyFeedRenderer rendering. alas this isn't working either, the breakpoint is hit every time.

Can anyone offer any advice on this matter? the documentation simply recommends turning it on on the actual feed item, not at the Rendering level, but neither seem to be working for me. Interestingly HTML caching is working elsewhere - is RSS also put into the HTML cache?

Thanks in advance,
Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请远离我 2024-12-16 19:27:55

- 确保提要定义项中的可缓存复选框已选中。

- 确保您已发布提要定义项。

- 如果您未填充 Feed 定义项中的“缓存持续时间”字段,则该字段应默认为一天。

-Feed 似乎缓存在 Sitecore.Synmination.FeedManager.Cache 中,而不是站点输出缓存中。调用 feed 后,在 Visual Studio 调试器中检查该缓存对象,然后在第二次调用该 feed 后再次检查,以尝试查看是否出现任何记录,以及同一 feed 是否出现多个缓存键。研究 Render() 方法;如果 PublicFeed.IsCacheable() 返回 false(取决于 feed 定义项中的 Cacheable 字段),则 PublicFeed.Render() 不会缓存。

- 确保没有其他任何东西会清除您对 feed 的请求之间的缓存。

SDN 论坛主题: http://sdn.sitecore.net/forum/ShowPost.aspx ?PostID=40591

-Ensure the Cacheable checkbox in the feed definition item is checked.

-Ensure that you have published the feed definition item.

-If you do not populate the Cache Duration field in the feed definition item, it should default to one day.

-Feeds appear to cache in Sitecore.Syndication.FeedManager.Cache rather than the site output cache. Inspect that cache object in the Visual Studio debugger after calling your feed, and then again after calling that feed a second time, to try to see if any records appear, and if multiple cache keys appear for the same feed. Investigate the Render() method; if PublicFeed.IsCacheable() returns false (depending on the Cacheable field in the feed definition item), PublicFeed.Render() does not cache.

-Ensure nothing else clears caches between your requests for the feed.

SDN forum thread: http://sdn.sitecore.net/forum/ShowPost.aspx?PostID=40591

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文