How do I cache an object loaded through SOAP from a third party that I use in forms? I am loading and object that I use to populate a form. Then on form submit I return some of the fields through SOAP back to the third party. On submit the form building function gets called and loads the object then the submit function gets called and loads the object again. How do I cache the object so that it is only loaded once but available to both or more function to act on it.
Would it not be possible for you to simply pass off the data you need in fields of #type =&gt; value? These are passed safely behind the scene through the entire form submission process, acting in a sense as the cache you are striving for.  Consider the following simplistic example :

$form['soap_data_email'] = array('#type' =&gt; 'value', '#value' =&gt; $soap_data_email);
$form['soap_data_name'] =  array('#type' =&gt; 'value', '#value' =&gt; $soap_data_name);


After submission, all your soap object's values would be available in the validation and submit callbacks of your form through the usual $form_state['values']['soap_data_email'] and   $form_state['values']['soap_data_name'] array.

If you have many variables this could all be factorised to be more efficient, but this should give you the basic idea.

This is the simplest way I can think of that lets you cache your data all across the form validation and submission process.