Google App Engine - Memcache - Java version of Python's client.add?

Posted by Spines on Stack Overflow See other posts from Stack Overflow or by Spines
Published on 2010-04-09T16:42:19Z Indexed on 2010/04/09 17:33 UTC
Read the original article Hit count: 404

Filed under:
|
|

The python interface to the memcache has an add method:

add(key, value, time=0, min_compress_len=0, namespace=None)

Sets a key's value, if and only if the item is not already in memcache. ...

The return value is True if added, False on error.

So with this you can add an item if it doesn't exist, and see if it previously existed by the return value.

The java memcache api equivalent for this doesn't let you know if there was a previous value or not:

put(key, value, expiration, MemcacheService.SetPolicy.ADD_ONLY_IF_NOT_PRESENT);

MemcacheService.SetPolicy.ADD_ONLY_IF_NOT_PRESENT: add the value if no value with the key, do nothing if the key exists

Is there a way to know if a previous value existed or not with the java api? I can't just check with the contains method beforehand, because in between the call to contains and the call to put, another JVM instance could modify the memcache.

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about memcache