Pieter Brinkman

Asp.Net: Caching Rss feeds

1 min readpieterASP.Net

For dotNetSearch.net I needed to cache the RSS feed (on the right). I did this with the .Net Cache namespace.

if(Cache.Get(RssUrl) == null) {
 RssDocument rssFeed = RssDocument.Load(new Uri(RssUrl));
 Cache.Insert(RssUrl, XDocument.Parse(rssFeed.ToXml(DocumentType.Rss)), null, DateTime.Now.AddMinutes(15), TimeSpan.Zero);
}
XDocument rssXml = (XDocument)Cache.Get(RssUrl);

In this examle I add the RSSFeed content as object in the cache and use the url of the RSS feed as Key. The Cache will expire (and cleared) after 15 minutes.