I found out the hard way that Twitter Pull doesn’t cache if the result is empty. The result is that it tries to pull the tweets each time the page load. It didn’t take long before I reached the rate limit on twitter. My solution was to add the empty result to the cache and handle it when pulling data from cache. My code:

function twitter_pull_retrieve($twitkey, $num_items = NULL) {
  // If $num_items is not set, use the default value.
  // This value is checked more rigorously in twitter_puller->check_arguments().
  $num_items = (intval($num_items) > 0) ? intval($num_items) : twitter_pull_num_items();

  // Cached value is specific to the Twitter key and number of tweets retrieved.
  $cache_key = $twitkey . '::' . $num_items;
  $cache = cache_get($cache_key, TWITTER_PULL_CACHE_TABLE);

  $tweets = array();

  if (!empty($cache) && !empty($cache->data)) {
    if($cache->data == "empty")  {
        return twitter_pull_empty_message();
    }
    $tweets =  $cache->data;
  }
  else {
    try {
      watchdog("twitter_pull","Feetching from twitter: " . $twitkey);
      $puller = new twitter_puller($twitkey, $num_items);
      $puller->get_items();
      $tweets = $puller->tweets;
    }
    catch (Exception $e) {
      return twitter_pull_empty_message();
    }

    if (!empty($tweets) && is_array($tweets)) {
      $cache_length = twitter_pull_cache_length() * 60; //-- in the settings we indicate length in minutes, here we need seconds.
      cache_set($cache_key, $tweets, TWITTER_PULL_CACHE_TABLE, time() + $cache_length);
    }
    else {
      $cache_length = twitter_pull_cache_length() * 60; //-- in the settings we indicate length in minutes, here we need seconds.
      cache_set($cache_key, "empty", TWITTER_PULL_CACHE_TABLE, time() + $cache_length);
    }
  }

  return $tweets;
}