@Override protected CASValue<Object> getForUpdateCAS(final String storageKey) throws ResourceIOException { try { return client.gets(storageKey); } catch (final OperationTimeoutException ex) { throw new MemcachedOperationTimeoutException(ex); } }
private IdentifiableValue getIdentifiable(final String key) { final CASValue<Object> casValue = client.gets(key); if (casValue != null) { return new SpyIdentifiableValue(casValue); } else { client.set(key, 0, NULL_VALUE); // use the fake null so that no other fetches get confused final CASValue<Object> try2 = client.gets(key); return try2 == null ? null : new SpyIdentifiableValue(try2); } }
/** * Gets (with CAS support) with a single key using the default transcoder. * * @param key the key to get * @return the result from the cache and CAS id (null if there is none) * @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 CASValue<Object> gets(String key) { return gets(key, transcoder); }
/** * Gets (with CAS support) with a single key using the default transcoder. * * @param key the key to get * @return the result from the cache and CAS id (null if there is none) * @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 CASValue<Object> gets(String key) { return gets(key, transcoder); }
/** * Gets (with CAS support) with a single key using the default transcoder. * * @param key the key to get * @return the result from the cache and CAS id (null if there is none) * @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 CASValue<Object> gets(String key) { return gets(key, transcoder); }
/** * Gets (with CAS support) with a single key using the default transcoder. * * @param key the key to get * @return the result from the cache and CAS id (null if there is none) * @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 CASValue<Object> gets(String key) { return gets(key, transcoder); }
/** * Gets (with CAS support) with a single key using the default transcoder. * * @param key the key to get * @return the result from the cache and CAS id (null if there is none) * @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 CASValue<Object> gets(String key) { return gets(key, transcoder); }
/** * Gets (with CAS support) with a single key using the default transcoder. * * @param key the key to get * @return the result from the cache and CAS id (null if there is none) * @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 CASValue<Object> gets(String key) { return gets(key, transcoder); }
@Override protected CASValue<Object> getForUpdateCAS(final String storageKey) throws ResourceIOException { try { return client.gets(storageKey); } catch (final OperationTimeoutException ex) { throw new MemcachedOperationTimeoutException(ex); } }
public void testGets() throws Exception { MemcachedClient client = bootstrapClient(); client.add("getskey", 10, "casValue").get(); CASValue<Object> val = client.gets("getskey"); long oldCas = val.getCas(); assertEquals("casValue", val.getValue()); client.replace("getskey", 10, "myNewVal").get(); val = client.gets("getskey"); assertEquals(oldCas + 1, val.getCas()); assertEquals("myNewVal", val.getValue()); }
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); }
public void testEmbeddedReplaceMemcachedCASTest() throws Exception { final String key1 = "5"; // 1. Put with Memcached Future<Boolean> f = cacheFactory.getMemcachedClient().set(key1, 0, "v1"); assertTrue(f.get(60, TimeUnit.SECONDS)); CASValue oldValue = cacheFactory.getMemcachedClient().gets(key1); // 2. Replace with Embedded assertTrue(cacheFactory.getEmbeddedCache().replace(key1, "v1", "v2")); // 4. Get with Memcached and verify value/CAS CASValue newValue = cacheFactory.getMemcachedClient().gets(key1); assertEquals("v2", newValue.getValue()); assertNotSame("The version (CAS) should have changed, " + "oldCase=" + oldValue.getCas() + ", newCas=" + newValue.getCas(), oldValue.getCas(), newValue.getCas()); }
public void testHotRodReplaceMemcachedCASTest() throws Exception { final String key1 = "6"; // 1. Put with Memcached Future<Boolean> f = cacheFactory.getMemcachedClient().set(key1, 0, "v1"); assertTrue(f.get(60, TimeUnit.SECONDS)); CASValue oldValue = cacheFactory.getMemcachedClient().gets(key1); // 2. Replace with Hot Rod VersionedValue versioned = cacheFactory.getHotRodCache().getVersioned(key1); assertTrue(cacheFactory.getHotRodCache().replaceWithVersion(key1, "v2", versioned.getVersion())); // 4. Get with Memcached and verify value/CAS CASValue newValue = cacheFactory.getMemcachedClient().gets(key1); assertEquals("v2", newValue.getValue()); assertTrue("The version (CAS) should have changed", oldValue.getCas() != newValue.getCas()); }
public void testEmbeddedHotRodReplaceMemcachedCASTest() throws Exception { final String key1 = "7"; // 1. Put with Memcached Future<Boolean> f = cacheFactory.getMemcachedClient().set(key1, 0, "v1"); assertTrue(f.get(60, TimeUnit.SECONDS)); CASValue oldValue = cacheFactory.getMemcachedClient().gets(key1); // 2. Replace with Hot Rod VersionedValue versioned = cacheFactory.getHotRodCache().getVersioned(key1); assertTrue(cacheFactory.getHotRodCache().replaceWithVersion(key1, "v2", versioned.getVersion())); // 3. Replace with Embedded assertTrue(cacheFactory.getEmbeddedCache().replace(key1, "v2", "v3")); // 4. Get with Memcached and verify value/CAS CASValue newValue = cacheFactory.getMemcachedClient().gets(key1); assertEquals("v3", newValue.getValue()); assertTrue("The version (CAS) should have changed", oldValue.getCas() != newValue.getCas()); }