Asp.Net: Caching Rss feeds

For 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.

Leave a Reply

Your email address will not be published. Required fields are marked *