Caching, It's a Good Thing
For our new Technology page, I had to write some code to handle the Twitter feed.* It seems like a pretty good strategy for dealing with Twitter. Basically, I set up a PHP script that uses cURL to fetch tweets from the Twitter API. Twitter sends back JSON, which I dump to a file. That runs, by cron, every hour. Then in the template for the Technology page, I parse the JSON file and display the tweets however I'd like.
This means I'm only making calls to the Twitter API when the cron runs (in my case, once per hour) instead of every time the page loads. That makes Twitter happy. It also means the page loads faster, because it's reading from the filesystem instead of waiting on a network response. Bonus: if, for whatever reason, Twitter sends back rubbish** my code can deal with that gracefully without hosing the rest of the page.
* Which is frustrating because there are a thousand Twitter modules and plugins but they never look/work the way anyone wants them to.
** Twitter API limits you to 150 calls per hour. Twice this week it has thrown that back at me. Since *I* am only making 1 call per hour, I wonder what else is going on. Usually I just kick the cron script and it's fine.