locked
Cache RSS XML feed RRS feed

  • Question

  • User-1668014665 posted

    HI, I am pull RSS XML into a usercontrol to show title of the RSS Title feeds only.

    I need to cache either/or the XML document or Web Stream ? I have tried a few methods but no luck. I need to cache the rss xml feed so that I dont travel down the www every time someone refreshes my blog page.

    rssURL is the url to get the feed...

    my code to get rss xml, so how is it done ????

            Dim rssStream As Stream = Nothing
            Dim myRequest As WebRequest = Nothing
            Dim myResponse As WebResponse = Nothing
    
            myRequest = WebRequest.Create(rssURL)
            myResponse = myRequest.GetResponse()
            rssStream = myResponse.GetResponseStream()
            rssDoc.Load(rssStream)
    
            Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")
    
            HERE on its just reading the XML
    
    




    Thursday, December 31, 2009 6:16 PM

Answers

  • User187056398 posted

    Something like this:

    Function GetCachedData() As XmlNodeList
    	Dim XList As XmlNodeList
    	' see if the list is in the cache.
    	XList = TryCast(Page.Cache("MyKey"), XmlNodeList)
    
    	If XList <> Nothing Then
    		Return XList
    	End If
    	' got cached version
    	' Code to read XList from source...
    	Dim XDoc As New XmlDataDocument()
    	XDoc.LoadXml("<root></root>")
    	XList = XDoc.SelectNodes("/")
    
    	' put the list in the cache so we don't have to read the disk again 
    	' unique key  
    	' object to store 
    	' no dependencies                          
    	' expire in one hour
    	Page.Cache.Insert("MyKey", XList, Nothing, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration)
    
    	Return XList
    
    End Function
    

     Original C# version (the comments are cleaner):

        XmlNodeList GetCachedData()
        {
            XmlNodeList XList;
            // see if the list is in the cache.
            XList = Page.Cache["MyKey"] as XmlNodeList;
    
            if (XList != null)
                return XList;   // got cached version
    
            // Code to read XList from source...
            XmlDataDocument XDoc = new XmlDataDocument();
            XDoc.LoadXml("<root></root>");
            XList = XDoc.SelectNodes("/");
    
            // put the list in the cache so we don't have to read the disk again 
            Page.Cache.Insert("MyKey",   // unique key  
                               XList,    // object to store 
                               null,     // no dependencies                          
                               DateTime.Now.AddHours(1),  // expire in one hour
                               Cache.NoSlidingExpiration); 
    
            return XList;              
        }


     


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 31, 2009 9:57 PM