/**
 * Get a random favorite photo from a Flickr user.
 *
 * @param   string  $userEmail Email address of a Flickr user
 * @return  object Phlickr_Photo
 */
function getRandomFavoritePhoto($userEmail)
{
    $api = new Phlickr_Api(FLICKR_API_KEY, FLICKR_API_SECRET);
    // load a saved cache file if it exists, set the expiration limit to a week.
    $api->setCache(Phlickr_Cache::createFrom(CACHE_FILE, 60 * 60 * 24 * 7));
    // select a random favorite photo
    $user = Phlickr_User::findByEmail($api, $userEmail);
    $favlist = $user->getFavoritePhotoList();
    $photo = $favlist->getRandomPhoto();
    assert(!is_null($photo));
    // serialize and save the cache file
    $api->getCache()->saveAs(CACHE_FILE);
    return $photo;
}