private void internalPut(String hashedKey, byte[] encodedValue, int expiration) { try { client.set(hashedKey, expiration, encodedValue); putCount.incrementAndGet(); putBytes.addAndGet(encodedValue.length); } catch (IllegalStateException e) { // operation did not get queued in time (queue is full) errorCount.incrementAndGet(); logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, e); } catch (Throwable t) { errorCount.incrementAndGet(); logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, t); } }
@Override public void put(NamedKey key, byte[] value) { try (final ResourceHolder<MemcachedClientIF> clientHolder = client.get()) { clientHolder.get().set( computeKeyHash(memcachedPrefix, key), expiration, serializeValue(key, value) ); } catch (IllegalStateException e) { // operation did not get queued in time (queue is full) errorCount.incrementAndGet(); log.warn(e, "Unable to queue cache operation"); } }
/** * @throws Exception If failed. */ @Test public void testSet() throws Exception { Assert.assertTrue(client.set("setKey", 0, "setVal").get()); assertEquals("setVal", jcache().get("setKey")); }
/** * @throws Exception If failed. */ @Test public void testSpecialTypes() throws Exception { Assert.assertTrue(client.set("boolKey", 0, true).get()); Assert.assertEquals(true, client.get("boolKey")); Assert.assertTrue(client.set("intKey", 0, 10).get()); Assert.assertEquals(10, client.get("intKey")); Assert.assertTrue(client.set("longKey", 0, 100L).get()); Assert.assertEquals(100L, client.get("longKey")); Date now = new Date(); Assert.assertTrue(client.set("dateKey", 0, now).get()); Assert.assertEquals(now, client.get("dateKey")); Assert.assertTrue(client.set("byteKey", 0, (byte) 1).get()); Assert.assertEquals((byte) 1, client.get("byteKey")); Assert.assertTrue(client.set("floatKey", 0, 1.1).get()); Assert.assertEquals(1.1, client.get("floatKey")); Assert.assertTrue(client.set("doubleKey", 0, 100.001d).get()); Assert.assertEquals(100.001d, client.get("doubleKey")); byte[] arr = new byte[5]; for (byte i = 0; i < arr.length; i++) arr[i] = i; Assert.assertTrue(client.set("arrKey", 0, arr).get()); assertArrayEquals(arr, (byte[])client.get("arrKey")); Assert.assertTrue(client.set("shortKey", 0, (short) 1).get()); Assert.assertEquals((short) 1, client.get("shortKey")); }
/** * @throws Exception If failed. */ @Test public void testComplexObject() throws Exception { Assert.assertTrue(client.set("objKey", 0, new ValueObject(10, "String")).get()); Assert.assertEquals(new ValueObject(10, "String"), client.get("objKey")); }
/** * @throws Exception If failed. */ @Test public void testSetWithExpiration() throws Exception { Assert.assertTrue(client.set("setKey", 2000, "setVal").get()); assertEquals("setVal", jcache().get("setKey")); Thread.sleep(2100); Assert.assertNull(jcache().get("setKey")); }
/** * @throws Exception If failed. */ @Test public void testReplaceWithExpiration() throws Exception { jcache().put("replaceKey", "replaceVal"); Assert.assertTrue(client.set("replaceKey", 2000, "replaceValNew").get()); assertEquals("replaceValNew", jcache().get("replaceKey")); Thread.sleep(2100); Assert.assertNull(jcache().get("replaceKey")); }
/** * @throws Exception If failed. */ @Test public void testCustomPort() throws Exception { customPort = 11212; Ignite g = startGrid(); assert g != null; assert g.cluster().nodes().size() == gridCount() + 1; MemcachedClientIF c = startClient(); Assert.assertTrue(c.set("key", 0, 1).get()); Assert.assertEquals(1, c.get("key")); c.shutdown(); stopGrid(); }
@Override public void put(Object key, Object value) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); try { this.memcachedClientIF.set((String) key, this.expiration, value).get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException e) { throw new IllegalArgumentException("Error writing key" + key, e); } }
public void putAll(Map<? extends String, ? extends V> t) { for (Map.Entry<? extends String, ? extends V> me : t.entrySet()) { client.set(getKey(me.getKey()), exp, me.getValue()); } }
public void putAll(Map<? extends String, ? extends V> t) { for(Map.Entry<? extends String, ? extends V> me : t.entrySet()) { client.set(getKey(me.getKey()), exp, me.getValue()); } }
public void putAll(Map<? extends String, ? extends V> t) { for (Map.Entry<? extends String, ? extends V> me : t.entrySet()) { client.set(getKey(me.getKey()), exp, me.getValue()); } }
@Override public boolean set(final String key, final int exp, final Object value) throws TimeoutException, CacheException { Future<Boolean> f = null; try { f = memcachedClient.set(key, exp, value); return f.get(); } catch (InterruptedException | ExecutionException e) { cancel(f); throw new CacheException(e); } }
public V put(String key, V value) { V rv = get(key); client.set(getKey(key), exp, value); return rv; } }
public V put(String key, V value) { V rv = get(key); client.set(getKey(key), exp, value); return rv; }
public V put(String key, V value) { V rv = get(key); client.set(getKey(key), exp, value); return rv; } }
public V put(String key, V value) { V rv = get(key); client.set(getKey(key), exp, value); return rv; } }
public V put(String key, V value) { V rv = get(key); client.set(getKey(key), exp, value); return rv; }
@Override public <T> boolean set(final String key, final int exp, final T value, final CacheTranscoder transcoder) throws TimeoutException, CacheException { Future<Boolean> f = null; try { f = memcachedClient.set(key, exp, value, getTranscoder(transcoder)); return f.get(); } catch (InterruptedException | ExecutionException e) { cancel(f); throw new CacheException(e); } }
public void putEntry(String url, HttpCacheEntry entry) throws IOException { byte[] bytes = serializeEntry(url, entry); String key = getCacheKey(url); if (key == null) return; try { client.set(key, 0, bytes); } catch (OperationTimeoutException ex) { throw new MemcachedOperationTimeoutException(ex); } }