views:

765

answers:

2

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 worng. I'm not using a handler... I'm just using a WCF service returning a Rss20FeedFormatter with the data

+1  A: 

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.

Joel Coehoorn
+6  A: 

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;
Kelsey
I appreciate the comments... but they do not answer my question... should I use the cache you are suggesting or just create a static file?
sebastian
All the feeds I have made have used one of these methods. I have never used a static file because it was so easy to not have worry about having to write new / replace files on the fly.
Kelsey