Passing data to an block I'm building an webinterface for our ticket system and I'm stuck. When you view an ticket and object Ticket is being made (containing the mails and etc.). Now on that same page I have enabled block (writen in the same module) to display some extra information.

Now the problem is, that extra information is found in the Ticket object that page creates. It's stupid to let the block fetch the ticket id and create that object all over again.

My question is, what is the most efficient way to pass that data to my blocks on that same page?
One method would be to create a central function that you can use to store the object you create, and return it from a static cache when required. That way you only need to create the object once, and other methods in the same page build can pick it up when they need it. 

The function might look like this:

function MYMODULE_new_ticket_cache($new_object = NULL) {
  // Register the static cache with the system
  $object = &amp;drupal_static(__FUNCTION__, NULL);

  // If we've been passed a new object, update the static cache to store that object
  if ($new_object) {
    $object = $new_object;
  }

  // In all cases, return the stored object (if it's NULL, that will indicate the object hasn't been stored yet)
  return $object;
}


When you create your object you would pass it to your caching function like so:

$ticket = function_to_create_new_ticket();
MYMODULE_new_ticket_cache($ticket);


Then in your hook_block_view() implementation you can inspect your cache to see if the object has been set, and use it:

$cached_ticket = MYMODULE_new_ticket_cache();

if ($cached_ticket) {
  // Build up your block content
}