title: Is this a good way to cache data in PHP?
body: <p>I've figured out a way to cache data (so that I won't have to re-access the database when the same data has already been fetched before), and I do it by using a static variable inside a function:</p>
  
  <pre><code>function get_user( $id, $flush=false ){
      static $cache;
      if ( isset($cache[$id]) &amp;&amp; !$flush )
          return $cache[$id];
      // Do something here to get user information
      $user_info = $value;
      // Return value after storing data into cache
      return $cache[$id] = $user_info;
  }
  </code></pre>
  
  <p>I'm not really sure if this is a good idea or maybe there's a better way to do caching. Is this a fine method or not? If not, then what are the disadvantages?</p>