title: Safely Handling Concurrent Memcache save in AppEngine
body: <p>I have in my application a lot of threads trying to put the same key in memcache. What I need to do is, once a thread managed to put that key then no other thread should put that key again.</p>
  
  <p>I've come across some mechanisms provided by memCache, like <code>putIFUnTouched</code> which I was trying to use like this: </p>
  
  <pre><code>IdentifiableValue value = memCache.getIdentifiable("item_id");
  mc.putIfUnTouched("item_id", null, "user_id"); 
  </code></pre>
  
  <p>But it gives me this Exception: <code>oldValue mustn't be null</code>.</p>
  
  <p>I also found <code>CAS</code> and I'm now confused which one of those I need to use in such situation. </p>
  
  <p>Thanks in advance.</p>