title: Memcached - Caching information that must be in synch with the DB
body: <p>I'm using <a href="http://memcached.org/" rel="nofollow">Memcached</a> as a Caching System and <a href="http://code.google.com/p/spymemcached/" rel="nofollow">Spymemcached</a> as a java client to store my Objects in the cache. <br></p>
  
  <p>Memcached put()/delete() are asynchronous.<br>
  For particular objects I need that the state in the Cache reflect the status of the DB.<br>
  For these objects I'm thinking of blocking the Thread on the Future returned by the spyMemcachedClient.put() method to be sure that the cache reflect the current status of the DB. <br></p>
  
  <p>something like</p>
  
  <pre><code>changedObject -&gt; block on Memcached.put() Future .. once it's finished -&gt;  writeToDB  = every subsequent Memcached.get() object is guaranteed to be in synch with the DB
  </code></pre>
  
  <p>If I don't synchronize and I hit the cache fast enough with a spyMemcachedClient.get() it might be that the object is not reflecting the current DB status.</p>
  
  <p>I'm wondering if it's correct to block on the put() for few kind of Objects or if this will decrease dramatically my Cache System performance? <br>
  Can I do something like that or I'm not really supposed to do so? </p>
  
  <p>Thanks</p>