C# 中 RSS 提要的最佳实现 (ASP.net)

发布于 2024-07-23 11:36:14 字数 249 浏览 6 评论 0原文

我有一个网络应用程序(asp.net),它需要一个提要。 因此,我使用 System.ServiceModel.Syndicate 命名空间来创建创建“新闻”的函数。 问题是每次有人调用它时它都会执行,我应该使用它来创建一个 xml 文件并使我的 rss url 指向该文件吗?

最好的方法是什么?

编辑:也许这就是我错的地方。 我没有使用处理程序...我只是使用 WCF 服务返回带有数据的 Rss20FeedFormatter。

The thing I have a web app (asp.net) which needs to have a feed. So I used the System.ServiceModel.Syndication namespace to create the function that creates the 'news'. The thing is it executes everytime somebody calls it, should I use it just to create an xml file and make my rss url point to the file?

What's the best approach?

Edit: Maybe that's where I'm wrong. I'm not using a handler... I'm just using a WCF service returning a Rss20FeedFormatter with the data.

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

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

发布评论

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

评论(3

掩于岁月 2024-07-30 11:36:14

过去,当我实现 RSS 时,我将 RSS 数据缓存在 HttpContext.Current.Cache 中。

RSS 数据通常不需要经常更新(例如,一分钟一次就足够了),因此您实际上只需每分钟访问一次数据库,而不是每次有人请求您的 RSS 数据时。

下面是如何使用缓存的示例:

// To save to the cache
HttpContext.Current.Cache.Insert("YourCachedName", pObjectToCache, null, DateTime.UtcNow.AddMinutes(1), System.Web.Caching.Cache.NoSlidingExpiration);
// To fetch from the cache
YourRssObject pObject = HttpContext.Current.Cache[("YourCachedName"] as YourRssObject : null;

您还可以在 ashx 中设置以下内容:

context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(1));

这将使您的 RSS 页面提供缓存版本,直到其过期。 这需要更少的资源,但如果您有其他东西使用 RSS 数据访问层调用,那么这将不会缓存该数据。

您还可以根据您的 RSS 可能收到的查询参数进行缓存,方法是:

context.Response.Cache.VaryByParams["YourQueryParamName"] = true;

In the past when I have implemented RSS I cached the RSS data in the HttpContext.Current.Cache.

RSS data usually doesn't have to get updated that often (eg. once a minute is more than enough) so you would only have to actually hit the DB once every minute instead of every single time someone requests your RSS data.

Here is an example of how to use the cache:

// To save to the cache
HttpContext.Current.Cache.Insert("YourCachedName", pObjectToCache, null, DateTime.UtcNow.AddMinutes(1), System.Web.Caching.Cache.NoSlidingExpiration);
// To fetch from the cache
YourRssObject pObject = HttpContext.Current.Cache[("YourCachedName"] as YourRssObject : null;

You could also set the following in your ashx:

context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(1));

This will make your RSS page serve up a cached version until it expires. This takes even less resources but if you have other things that use your RSS data access layer calls then this will not cache that data.

You can also make it cache based on a query param that your RSS might receive as well by setting:

context.Response.Cache.VaryByParams["YourQueryParamName"] = true;
何其悲哀 2024-07-30 11:36:14

ASP.Net 内置了一些非常好的服务器端缓存。假设您使用这些类作为普通 aspx 页面或 http 处理程序 (ashx) 的一部分,您可以告诉 ASP.Net 主动缓存它,而不是重新构建您的满足每个请求。

ASP.Net has some pretty good server-side caching built in. Assuming you are using these classes as part of normal aspx page or http handler (ashx), you can just tell ASP.Net to cache it aggressively rather than re-build your feed on each request.

幻梦 2024-07-30 11:36:14

在您的 .aspx 页面中,您不能只使用:

<%@ OutputCache Duration="60" VaryByParam="none" %>

我有一篇博客文章,其中我将存储过程的结果作为 RSS 提要发送到我的手机 此处。

In your .aspx page can't you just use:

<%@ OutputCache Duration="60" VaryByParam="none" %>

I have a blog posting where I have the results of a stored proc sent to my phone as an RSS feed HERE.

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