More efficient use of function by storing the result?
Seeing as how the data is not really an item that is cachable sitewide, you could quite easily use the $_SESSION variable.

Example:

function my_expensive_function($foo, $bar) {
  if (isset($_SESSION['my_really_cool_stuff'])) {
    return $_SESSION['my_really_cool_stuff'];
  }
  else {
    //Do what you would normally do to get everything you need
    //and put it in a $my_really_cool_stuff variable
    $_SESSION['my_really_cool_stuff'] = $my_really_cool_stuff;
    return $my_really_cool_stuff;
  }
}


This way, if the data already exists in the user session, it'll return that.  If not, then it'll generate it, put it in the session, and then return it.

You can put the $_SESSION data into a theme function and make it available to templates as well if you wish, but that's probably a separate question (and you'd have to make sure you had a fallback in case the session data had not been set).