Ingeniux Runtime RSS Caching

Washington and Lee University uses a number of RSS feeds on its homepage to keep site visitors informed. Feeds include:

  • WordPress News Blog
  • WordPress Status Blog
  • Twitter Stream
  • Custom Calendar Events RSS

Shortly after launching our new site, we met the infamous Twitter fail whale. Load issues with Twitter’s RSS feed ground the loading of our homepage to a halt. That’s when we decided to look into runtime caching. We implemented a rudimentary ASP script to seek out the Twitter RSS feed on a regular interval and save the contents of the feed to a local file. We then instructed our Ingeniux page to retrieve this local file. By doing so, we minimized the risk of hitting the fail whale and, to our delight, found that the entire page loaded more quickly. So, we extended the caching to our other feeds. The system is not without flaws, and there are areas for augmenting the script to catch a few other potential problems, but we’re sailing much more smoothly now.

Pros:

  • Our homepage loads faster.
  • We are less susceptible to periodic Twitter or WordPress outages.

Cons:

  • We lost the “instant” update capabilities of RSS. We retrieve our Twitter and WordPress Status feeds every 10 minutes and our WordPress News and Calendar feeds every hour.

~~

HOW TO

On the runtime server, in the “custom” folder, we added a classic ASP file. This is the file that we indicate as the source of the RSS feed in Ingeniux. Let’s call this file “twitter.asp.” Here’s the code:

<!–#include file=”asp_cache.asp”–>
<%
If cacheFileIsExpired(“twitter_feed.xml”, 1, “hours”) Then
Response.Buffer = True
Dim objXMLHTTP, xml
Set xml = Server.CreateObject(“MSXML2.ServerXMLHTTP”)
xml.Open “GET”, “http://twitter.com/statuses/user_timeline/20787409.rss?count=2&#8243;, False
xml.Send
strPosts = xml.responseText
Set xml = Nothing
Response.Write(writeCachedFile(“twitter_feed.xml”, strPosts))
Else
Response.Write(getCachedFile(“twitter_feed.xml”))
End If
%>

The script first checks to see if the modified date of the local file has exceeded the specified interval. The name of the local file is “twitter_feed.xml.”  If we’re within the time interval, the ASP script simply returns the content of the local file as fully formatted XML. If not, it retrieves the RSS feed from the source and saves the XML to the local file. The time interval is specified in the first line as a numeral and a unit of measurement (i.e, 10 minutes or 1 hour).

The “twitter.asp” file includes an additional file called “asp_cache.asp.” This file declares a few key variables and routines, and, most importantly, specifies where you are saving and retrieving the local file. In our case, that’s a folder at “d:\WebSites\v6\Custom\cache\files\” on our runtime site. Here’s the code:

<%
Function cacheFileIsExpired(strFileName, cacheInterval, cacheIntervalUnit)
If cacheInterval = 0 Then
cacheFileIsExpired = True
Exit Function
End If
On Error Resume Next
Dim cacheFSO : Set cacheFSO = CreateObject(“Scripting.FileSystemObject”)
Dim cacheFile : Set cacheFile = cacheFSO.GetFile(“d:\WebSites\v6\Custom\cache\files\” & strFileName)
Dim strDate : strDate = cacheFile.DateLastModified
Set objFile = Nothing

Select Case cacheIntervalUnit
Case “minutes” : strUnit = “n”
Case “hours” : strUnit = “h”
Case “days” : strUnit = “d”
End Select
cacheFileIsExpired = (DateDiff(strUnit,CDate(strDate), Now()) > cacheInterval)
If err.Number <> 0 Then
cacheFileIsExpired = True
End If
Set cacheFile = Nothing
Set cacheFSO = Nothing
End Function

Function writeCachedFile(strFileName, strText)
Dim cacheFSO : Set cacheFSO = CreateObject(“Scripting.FileSystemObject”)
Dim cacheFile : Set cacheFile = cacheFSO.CreateTextFile(“d:\WebSites\v6\Custom\cache\files\” & strFileName, True, True)
cacheFile.Write(strText)
cacheFile.Close
Set cacheFile = Nothing
Set cacheFSO = Nothing
writeCachedFile = strText
End Function

Function getCachedFile(strFileName)
Dim cacheFSO : Set cacheFSO = CreateObject(“Scripting.FileSystemObject”)
Dim cacheFile : Set cacheFile = cacheFSO.OpenTextFile(“d:\WebSites\v6\Custom\cache\files\” & strFileName,1,False,-1)
getCachedFile = cacheFile.ReadAll
Set cacheFile = Nothing
Set cacheFSO = Nothing
End Function
%>

That’s it. Just remember to specify your “twitter.asp” page as the source of your RSS feed in Ingeniux. I hope this can be helpful to other Ingeniux users. If you have ideas to improve this utility or something else you’d like to share, please do so.

- Eric Owsley

About these ads

1 Response to “Ingeniux Runtime RSS Caching”


  1. 1 David Hillis January 27, 2010 at 4:04 am

    Great solution to the “Fail Whale” challenge Eric. Thanks for sharing. I will need to reference on the Ingeniux blog for other customers to see as well.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




RSS Web Services Events

  • An error has occurred; the feed is probably down. Try again later.

Of Interest


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: