title: Wordpress - Global Variable with Stateful Scope vs WP Options Caching Issue
body: <p>Here is the problem.</p>
  
  <p>I need to increment a domain specific order number every time an order is placed in woocommerce.  </p>
  
  <p>I tried using the wp_option functionality, so that it would be present no matter where or when it runs.  I used the following helper functions.</p>
  
  <pre><code>    $this-&gt;$order_number = get_option('next_order_number'); // To retrieve next number
      update_option('next_order_number',$this-&gt;$order_number +1); // To update number
  
  return $this-&gt;$order_number;
  </code></pre>
  
  <p>The problem I am having is that when two orders come in back to back, close enough in time, get_option is returning the same order number.  </p>
  
  <p>So, either the caching update is too slow or too stupid to figure out that I am accessing the same variable in both execution contexts.</p>
  
  <p>In the .NET world, we could do a lot of different things to solve this.  However, I am new to wordpress and I don't have a good idea of how to handle this anomoly.</p>
  
  <p>My thoughts were to create a Singleton Class, and increment the number internally and return the integer, then trigger an update to the wp_options.</p>
  
  <p>Assuming the singleton worked across all wordpress requests, I could bolt on a little extra glue to grab the current value if it was reset due to a server reboot, etc...</p>
  
  <p>However, even when creating a static variable for use in singleton pattern, the value isn't persisting across requests.</p>
  
  <p>I am starting to think that PHP/Wordpress doesn't support any type of application state similar to Microsoft MVC.  </p>
  
  <p>Is there any hook or technique I can leverage where I can fire up a Global variable that persist state and live across all requests from all users, and re-init itself when the process recycles.</p>