@Override protected boolean updateCAS( final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException { final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject); return casResult == CASResponse.OK; }
public Set<String> putIfUntouched(final Map<String, CasPut> values) { final Set<String> successes = new HashSet<>(); values.forEach((key, vals) -> { final long cas = ((SpyIdentifiableValue)vals.getIv()).getCasValue().getCas(); final CASResponse response = client.cas(key, cas, vals.getExpirationSeconds(), toCacheValue(vals.getNextToStore())); if (response == CASResponse.OK) { successes.add(key); } }); return successes; }
/** * Perform a synchronous CAS operation. * * @param <T> * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @param tc the transcoder to serialize and unserialize the value * @return a CASResponse * @throws OperationTimeoutException if global operation timeout is exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ @Override public <T> CASResponse cas(String key, long casId, T value, Transcoder<T> tc) { return cas(key, casId, 0, value, tc); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue * is too full to accept any more requests */ public CASResponse cas(String key, long casId, Object value) { return cas(key, casId, value, transcoder); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ public CASResponse cas(String key, long casId, Object value) { return cas(key, casId, value, transcoder); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ @Override public CASResponse cas(String key, long casId, Object value) { return cas(key, casId, value, transcoder); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue * is too full to accept any more requests */ public CASResponse cas(String key, long casId, Object value) { return cas(key, casId, value, transcoder); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue * is too full to accept any more requests */ public CASResponse cas(String key, long casId, Object value) { return cas(key, casId, value, transcoder); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param exp the expiration of this object * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ public CASResponse cas(String key, long casId, int exp, Object value) { return cas(key, casId, exp, value, transcoder); }
/** * Perform a synchronous CAS operation. * * @param <T> * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @param tc the transcoder to serialize and unserialize the value * @return a CASResponse * @throws OperationTimeoutException if global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue * is too full to accept any more requests */ public <T> CASResponse cas(String key, long casId, T value, Transcoder<T> tc) { return cas(key, casId, 0, value, tc); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ @Override public CASResponse cas(String key, long casId, Object value) { return cas(key, casId, value, transcoder); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param exp the expiration of this object * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ @Override public CASResponse cas(String key, long casId, int exp, Object value) { return cas(key, casId, exp, value, transcoder); }
/** * Perform a synchronous CAS operation. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @param tc the transcoder to serialize and unserialize the value * @return a CASResponse * @throws OperationTimeoutException if global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue * is too full to accept any more requests */ public <T> CASResponse cas(String key, long casId, T value, Transcoder<T> tc) { return cas(key, casId, 0, value, tc); }
/** * Perform a synchronous CAS operation. * * @param <T> * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @param tc the transcoder to serialize and unserialize the value * @return a CASResponse * @throws OperationTimeoutException if global operation timeout is exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ public <T> CASResponse cas(String key, long casId, T value, Transcoder<T> tc) { return cas(key, casId, 0, value, tc); }
/** * Perform a synchronous CAS operation with the default transcoder. * * @param key the key * @param casId the CAS identifier (from a gets operation) * @param exp the expiration of this object * @param value the new value * @return a CASResponse * @throws OperationTimeoutException if the global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ @Override public CASResponse cas(String key, long casId, int exp, Object value) { return cas(key, casId, exp, value, transcoder); }
/** * Perform a synchronous CAS operation. * * @param <T> * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @param tc the transcoder to serialize and unserialize the value * @return a CASResponse * @throws OperationTimeoutException if global operation timeout is exceeded * @throws IllegalStateException in the rare circumstance where queue is too * full to accept any more requests */ @Override public <T> CASResponse cas(String key, long casId, T value, Transcoder<T> tc) { return cas(key, casId, 0, value, tc); }
/** * Perform a synchronous CAS operation. * * @param <T> * @param key the key * @param casId the CAS identifier (from a gets operation) * @param value the new value * @param tc the transcoder to serialize and unserialize the value * @return a CASResponse * @throws OperationTimeoutException if global operation timeout is * exceeded * @throws IllegalStateException in the rare circumstance where queue * is too full to accept any more requests */ public <T> CASResponse cas(String key, long casId, T value, Transcoder<T> tc) { return cas(key, casId, 0, value, tc); }
@Override protected boolean updateCAS( final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException { final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject); return casResult == CASResponse.OK; }
public void testCas() throws Exception { MemcachedClient client = bootstrapClient(); client.add("caskey", 10, "casValue").get(); CASValue<Object> val = client.gets("caskey"); assertEquals("casValue", val.getValue()); CASResponse r = client.cas("caskey", val.getCas(), "newValue"); assertEquals(CASResponse.OK, r); r = client.cas("caskey", val.getCas(), "newValue2"); assertEquals(CASResponse.EXISTS, r); }
/** * Tries to update an object value in memcached considering the cas validation * * Returns true if the object passed the cas validation and was modified. * * @param keyString * @param value * @return */ private boolean storeInMemcached(String keyString, ObjectWithCas value) { if (value != null && value.getObject() != null && !Serializable.class.isAssignableFrom(value.getObject().getClass())) { throw new CacheException("Object of type '" + value.getObject().getClass().getName() + "' that's non-serializable is not supported by Memcached"); } CASResponse response; if (configuration.isCompressionEnabled()) { response = client.cas(keyString, value.getCas(), value.getObject(), new CompressorTranscoder()); } else { response = client.cas(keyString, value.getCas(), value.getObject()); } return (response.equals(CASResponse.OBSERVE_MODIFIED) || response.equals(CASResponse.OK)); }