@Override public <T> T get(String key, Transcoder<T> tc) { CachedData data = theMap.get(key); return data != null ? tc.decode(data) : null; }
@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; }
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; } }
final T theValue = data != null ? tc.decode(data) : null;
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()))); } });
if (metadataMap.containsKey(key)) { CachedData val = metadataMap.remove(key); returnMap.put(key, tc.decode(val)); if (data != null && checksumPass) { final CachedData cd = new CachedData(ci.getFlags(), data, Integer.MAX_VALUE); returnMap.put(ci.getKey(), tc.decode(cd)); } else { returnMap.put(ci.getKey(), null);
if (metadataMap.containsKey(key)) { CachedData val = metadataMap.remove(key); returnMap.put(key, tc.decode(val)); if (data != null && checksumPass) { final CachedData cd = new CachedData(ci.getFlags(), data, Integer.MAX_VALUE); returnMap.put(ci.getKey(), tc.decode(cd)); } else { returnMap.put(ci.getKey(), null);
final Transcoder<T> transcoder = (tc == null ? (Transcoder<T>) evcacheMemcachedClient.getTranscoder() : tc); return transcoder.decode((CachedData) cd.getData()); } else { final List<String> keys = cd.getChunkKeys(); final Transcoder<T> transcoder = (tc == null ? (Transcoder<T>) evcacheMemcachedClient.getTranscoder() : tc); return transcoder.decode(new CachedData(ci.getFlags(), data, Integer.MAX_VALUE));
if (cd.getData() == null) return Single.just(null); final Transcoder<T> transcoder = (tc == null ? (Transcoder<T>) evcacheMemcachedClient.getTranscoder() : tc); return Single.just(transcoder.decode((CachedData) cd.getData())); } else { final List<String> keys = cd.getChunkKeys(); final Transcoder<T> transcoder = (tc == null ? (Transcoder<T>) evcacheMemcachedClient.getTranscoder() : tc); return transcoder.decode(new CachedData(ci.getFlags(), data, Integer.MAX_VALUE)); });
/** * {@inheritDoc} */ public Object decode( final CachedData cachedData ) { return _delegate.decode( cachedData ); }
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); } }
public <T> Single<T> get(String key, Transcoder<T> tc, boolean _throwException, boolean hasZF, boolean chunked, Scheduler scheduler) throws Exception { if (chunked) { return assembleChunks(key, _throwException, 0, tc, hasZF, scheduler); } 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 Single.just((T)evcacheMemcachedClient.getTranscoder().decode(cd)); } else { return Single.just(tc.decode(cd)); } } else { return null; } } else { return evcacheMemcachedClient.asyncGet(key, tc, null) .get(readTimeout.get(), TimeUnit.MILLISECONDS, _throwException, hasZF, scheduler); } }
public void gotData(String k, int flags, long cas, byte[] data) { assert key.equals(k) : "Wrong key returned"; assert cas > 0 : "CAS was less than zero: " + cas; val = new CASValue<T>(cas, tc.decode(new CachedData(flags, data, tc.getMaxSize()))); }
@Override public T decode(CachedData cachedData) { int flags = cachedData.getFlags(); boolean compressed = (flags & compressionFlag) > 0; byte[] decodedBytes = cachedData.getData(); if (compressed) { decodedBytes = decompressor.decompress(cachedData.getData()); } return wrappedTranscoder.decode(new CachedData(flags, decodedBytes, getMaxSize())); }