Package net.spy.memcached
Class CASMutator<T>
java.lang.Object
net.spy.memcached.compat.SpyObject
net.spy.memcached.CASMutator<T>
Object that provides mutation via CAS over a given memcache client.
Example usage (reinventing incr):
// Get or create a client. MemcachedClient client=[...]; // Get a Transcoder. Transcodertc = new LongTranscoder(); // Get a mutator instance that uses that client. CASMutator<Long> mutator=new CASMutator<Long>(client, tc); // Get a mutation that knows what to do when a value is found. CASMutation<Long> mutation=new CASMutation<Long>() { public Long getNewValue(Long current) { return current + 1; } }; // Do a mutation. long currentValue=mutator.cas(someKey, 0L, 0, mutation);
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MemcachedClientIF
private final int
private static final int
private final Transcoder
<T> -
Constructor Summary
ConstructorsConstructorDescriptionCASMutator
(MemcachedClientIF c, Transcoder<T> tc) Construct a CASMutator that uses the given client.CASMutator
(MemcachedClientIF c, Transcoder<T> tc, int maxTries) Construct a CASMutator that uses the given client. -
Method Summary
-
Field Details
-
MAX_TRIES
private static final int MAX_TRIES- See Also:
-
client
-
transcoder
-
max
private final int max
-
-
Constructor Details
-
CASMutator
Construct a CASMutator that uses the given client.- Parameters:
c
- the clienttc
- the Transcoder to usemaxTries
- the maximum number of attempts to get a CAS to succeed
-
CASMutator
Construct a CASMutator that uses the given client.- Parameters:
c
- the clienttc
- the Transcoder to use
-
-
Method Details
-
cas
CAS a new value in for a key.Note that if initial is null, this method will only update existing values.
- Parameters:
key
- the key to be CASedinitial
- the value to use when the object is not cachedinitialExp
- the expiration time to use when initializingm
- the mutation to perform on an object if a value exists for the key- Returns:
- the new value that was set
- Throws:
Exception
-