Twitter integration on lucidity.ie
One of the things we wanted for the homepage of our site was twitter integration. I wanted to display the most recent 2 tweets from our twitter page. In this post I will discuss how I did this and how I optimized it in a way that minimized the impact on page response time.
The first step was to get the tweets. Since the site is built with Ruby on Rails, I was able to use the excellent twitter gem. Using this gem, getting the public timeline of statuses for any user is just one line of code:Twitter::Base.new('luciditytech', 'password').timeline(:user)
However I noticed that it took about 1-2 seconds to retrieve this data. This was far too much time to add to each page load. The twitter statuses would have to be cached in some way. Since they would not be changing too often, I wrote a rake task that would run every few minutes and would update a locally cached list of statuses stored in memcached. The site would then just use the list stored in memcached for every request.
The code for the rake task and the class for retrieving the statuses is available on github.
- Dermot07 April 2009 11:02 | Posted by Dermot

No comments yet.