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.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With