@Override public CachedData encode(Object o) { if (o != null && o instanceof CachedData) return (CachedData) o; return super.encode(o); }
@Override public Object decode(CachedData d) { return super.decode(d); }
@Override public boolean asyncDecode(CachedData d) { return super.asyncDecode(d); }
@Override public <T> T get(String key, Transcoder<T> tc) { CachedData data = theMap.get(key); return data != null ? tc.decode(data) : null; }
@Deprecated public <T> Future<Boolean> add(String key, int exp, T value, final Transcoder<T> tc, EVCacheLatch latch) throws Exception { final CachedData cd; if (value instanceof CachedData) { cd = (CachedData) value; } else { if(tc == null) { cd = getTranscoder().encode(value); } else { cd = tc.encode(value); } } return _add(key, exp, cd, latch); }
public void gotData(String k, int flags, long cas, byte[] data) { if (!key.equals(k)) log.warn("Wrong key returned. Key - {}; Returned Key {}", key, k); if (data != null) { if(getAndTouchDataSize == null) getAndTouchDataSize = EVCacheMetricsFactory.getDistributionSummary(appName + "-GATOperation-DataSize", appName, serverGroup.getName()); if (getAndTouchDataSize != null) getAndTouchDataSize.record(data.length); } val = new CASValue<T>(cas, tc.decode(new CachedData(flags, data, tc.getMaxSize()))); } });
@Override public void gotData(String k, int flags, byte[] data) { if (data != null) { if(bulkDataSize == null) bulkDataSize = EVCacheMetricsFactory.getDistributionSummary(appName + "-BulkOperation-DataSize", appName, serverGroup.getName()); if (bulkDataSize != null) bulkDataSize.record(data.length); } m.put(k, tcService.decode(tc, new CachedData(flags, data, tc.getMaxSize()))); }
@Override protected void setUp() throws Exception SerializingTranscoder transcoder = new SerializingTranscoder( 50 * 1024 * 1024 // 50 MB ); transcoder.setCompressionThreshold(Integer.MAX_VALUE);
public MockMemcachedClient() { transcoder = new LZ4Transcoder(); transcoder.setCompressionThreshold(0); }
final T theValue = data != null ? tc.decode(data) : null;
@Deprecated public <T> Future<Boolean> add(String key, int exp, T value, Transcoder<T> tc) throws Exception { final CachedData cd; if (value instanceof CachedData) { cd = (CachedData) value; } else { if(tc == null) { cd = getTranscoder().encode(value); } else { cd = tc.encode(value); } } return _add(key, exp, cd, null); }
@SuppressWarnings("unchecked") public void gotData(String k, int flags, byte[] data) { if (data != null) { if(getDataSize == null) getDataSize = EVCacheMetricsFactory.getDistributionSummary(appName + "-GetOperation-DataSize", appName, serverGroup.getName()); if (getDataSize != null) getDataSize.record(data.length); } if (!key.equals(k)) log.warn("Wrong key returned. Key - {}; Returned Key {}", key, k); if (tc == null) { if (tcService == null) { log.error("tcService is null, will not be able to decode"); throw new RuntimeException("TranscoderSevice is null. Not able to decode"); } else { final Transcoder<T> t = (Transcoder<T>) getTranscoder(); val = tcService.decode(t, new CachedData(flags, data, t.getMaxSize())); } } else { if (tcService == null) { log.error("tcService is null, will not be able to decode"); throw new RuntimeException("TranscoderSevice is null. Not able to decode"); } else { val = tcService.decode(tc, new CachedData(flags, data, tc.getMaxSize())); } } }
private T getFromObj(Object obj) { if(obj != null && obj instanceof EVCacheValue) { final EVCacheValue val = (EVCacheValue)obj; final CachedData cd = new CachedData(val.getFlags(), val.getValue(), CachedData.MAX_SIZE); if(tc == null) { if(_transcoder == null) { return (T)client.getTranscoder().decode(cd); } else { return (T)_transcoder.decode(cd); } } else { return tc.decode(cd); } } else { return null; } }
@Override public <T> Future<Boolean> set(String key, int exp, T o, Transcoder<T> tc) theMap.put(key, tc.encode(o));
@Override public Map<String, T> get() { Map<String, T> retVal = new HashMap<>(); while (keys.hasNext()) { String key = keys.next(); CachedData data = theMap.get(key); retVal.put(key, data != null ? tc.decode(data) : null); } return retVal; }
@Deprecated public <T> Future<Boolean> add(String key, int exp, T value) throws Exception { final CachedData cd; if (value instanceof CachedData) { cd = (CachedData) value; } else { cd = getTranscoder().encode(value); } return _add(key, exp, cd, null); }
@Deprecated public <T> Future<Boolean> replace(String key, T value, int timeToLive, EVCacheLatch evcacheLatch) throws Exception { final CachedData cd; if (value instanceof CachedData) { cd = (CachedData) value; } else { cd = getTranscoder().encode(value); } return _replace(key, cd, timeToLive, evcacheLatch); }
public <T> T get(String key, Transcoder<T> tc, boolean _throwException, boolean hasZF, boolean chunked) throws Exception { if (chunked) { return assembleChunks(key, false, 0, tc, hasZF); } else if(shouldHashKey()) { final String hKey = getHashedKey(key); final Object obj = evcacheMemcachedClient.asyncGet(hKey, evcacheValueTranscoder, null).get(readTimeout.get(), TimeUnit.MILLISECONDS, _throwException, hasZF); if(obj instanceof EVCacheValue) { final EVCacheValue val = (EVCacheValue)obj; if(val == null || !(val.getKey().equals(key))) { EVCacheMetricsFactory.increment(appName, null, serverGroup.getName(), appName + "-KEY_HASH_COLLISION"); return null; } final CachedData cd = new CachedData(val.getFlags(), val.getValue(), CachedData.MAX_SIZE); if(tc == null) { return (T)evcacheMemcachedClient.getTranscoder().decode(cd); } else { return tc.decode(cd); } } else { return null; } } else { return evcacheMemcachedClient.asyncGet(key, tc, null).get(readTimeout.get(), TimeUnit.MILLISECONDS, _throwException, hasZF); } }
@Deprecated public <T> Future<Boolean> set(String key, T value, int timeToLive, EVCacheLatch evcacheLatch) throws Exception { final CachedData cd; if (value instanceof CachedData) { cd = (CachedData) value; } else { cd = getTranscoder().encode(value); } return _set(key, cd, timeToLive, evcacheLatch); }