Usually I do:
if not memcache.get('mykey'):
memcache.set('mykey', item)
However, today I saw memcache.add(), which appears to add an item only if it doesn't already exist. So is this equivalent to the code I have above? Can I just replace the code above with memcache.add()?
Also, and more importantly, I'm using AppStats, and under RPC Call Traces, I get to see if my request calls memcache.set() or get() or datastore.put() or get(). When using the 2 lines of code above, I don't see anything for memcache.set(), which is expected. However, using only memcache.add() (without checking if the item already exists) always calls memcache.set(), even though memcache.add() returned false (meaning a new item was not inserted). Why is this the case?