/** * @throws Exception If failed. */ @Test public void testAdd() throws Exception { jcache().put("addKey1", "addVal1"); Assert.assertFalse(client.add("addKey1", 0, "addVal1New").get()); Assert.assertTrue(client.add("addKey2", 0, "addVal2").get()); assertEquals("addVal1", jcache().get("addKey1")); assertEquals("addVal2", jcache().get("addKey2")); }
/** * @throws Exception If failed. */ @Test public void testAddWithExpiration() throws Exception { Assert.assertTrue(client.add("addKey", 2000, "addVal").get()); assertEquals("addVal", jcache().get("addKey")); Thread.sleep(2100); Assert.assertNull(jcache().get("addKey")); }
public void saveInternal(final String proxyGrantingTicketIou, final String proxyGrantingTicket) { handleSynchronousRequest(this.client.add(proxyGrantingTicketIou, 120, proxyGrantingTicket)); }
@Override public boolean add(final String key, final int exp, final Object value) throws TimeoutException, CacheException { Future<Boolean> f = null; try { f = memcachedClient.add(key, exp, value); return f.get(); } catch (InterruptedException | ExecutionException e) { cancel(f); throw new CacheException(e); } }
@Override public boolean add(final String key, final int exp, final Object value) throws TimeoutException, CacheException { Future<Boolean> f = null; try { f = memcachedClient.add(key, exp, value); return f.get(); } catch (InterruptedException | ExecutionException e) { cancel(f); throw new CacheException(e); } }
/** * <b>IMPORTANT:</b> This operation is not atomic as the underlying implementation (memcached) does not provide a * way to do it. */ @Override public ValueWrapper putIfAbsent(Object key, Object value) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); ValueWrapper valueWrapper = get(key); if (valueWrapper == null) { try { this.memcachedClientIF.add((String) key, this.expiration, value).get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException e) { throw new IllegalArgumentException("Error writing key" + key, e); } return null; } else { return valueWrapper; } }
/** * <b>IMPORTANT:</b> This operation is not atomic as the underlying implementation (memcached) does not provide a * way to do it. */ @Override public ValueWrapper putIfAbsent(Object key, Object value) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); ValueWrapper valueWrapper = get(key); if (valueWrapper == null) { try { this.memcachedClientIF.add((String) key, this.expiration, value).get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException e) { throw new IllegalArgumentException("Error writing key" + key, e); } return null; } else { return valueWrapper; } }
@Override public ComposableFuture<Boolean> setIfAbsentAsync(final K key, final V value) { return SpyFutureHelper.fromOperation(() -> spyClient.add(keyTranslator.translateKey(key), expirationSpyUnits, value)); }
@Override public <T> boolean add(final String key, final int exp, final T value, final CacheTranscoder transcoder) throws TimeoutException, CacheException { Future<Boolean> f = null; try { f = memcachedClient.add(key, exp, value, getTranscoder(transcoder)); return f.get(); } catch (InterruptedException | ExecutionException e) { cancel(f); throw new CacheException(e); } }
@Override public <T> boolean add(final String key, final int exp, final T value, final CacheTranscoder transcoder) throws TimeoutException, CacheException { Future<Boolean> f = null; try { f = memcachedClient.add(key, exp, value, getTranscoder(transcoder)); return f.get(); } catch (InterruptedException | ExecutionException e) { cancel(f); throw new CacheException(e); } }
done = true; rv = null; } else if (client.add(key, initialExp, initial, transcoder).get()) { done = true; rv = initial;
done = true; rv = null; } else if(client.add(key, initialExp, initial, transcoder).get()) { done=true; rv=initial;
done = true; rv = null; } else if (client.add(key, initialExp, initial, transcoder).get()) { done = true; rv = initial;
done = true; rv = null; } else if (client.add(key, initialExp, initial, transcoder).get()) { done = true; rv = initial;
done = true; rv = null; } else if(client.add(key, initialExp, initial, transcoder).get()) { done=true; rv=initial;
done = true; rv = null; } else if (client.add(key, initialExp, initial, transcoder).get()) { done = true; rv = initial;
() -> spyClient.add(cacheKey, expirationSpyUnits, newValue));