From 6e542b37c85c073c70a9755d0613a42ca29bc615 Mon Sep 17 00:00:00 2001 From: Shashi Madappa Date: Tue, 8 Sep 2020 21:17:45 -0700 Subject: [PATCH] Fixed issue with transcoding multiple times --- .../java/com/netflix/evcache/EVCacheImpl.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java index 55b8d67a..07601f79 100644 --- a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java +++ b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java @@ -1917,20 +1917,24 @@ protected EVCacheLatch set(String key, T value, Transcoder tc, int timeTo for (EVCacheClient client : clients) { String canonicalKey = evcKey.getCanonicalKey(client.isDuetClient()); String hashKey = evcKey.getHashKey(client.isDuetClient(), client.getHashingAlgorithm(), client.shouldEncodeHashKey(), client.getMaxHashingBytes()); - if (tc != null) { - cd = tc.encode(value); - } else if (_transcoder != null) { - cd = ((Transcoder) _transcoder).encode(value); - } else { - cd = client.getTranscoder().encode(value); + if(cd == null) { + if (tc != null) { + cd = tc.encode(value); + } else if (_transcoder != null) { + cd = ((Transcoder) _transcoder).encode(value); + } else { + cd = client.getTranscoder().encode(value); + } } if (hashKey != null) { final EVCacheValue val = new EVCacheValue(canonicalKey, cd.getData(), cd.getFlags(), timeToLive, System.currentTimeMillis()); - cd = evcacheValueTranscoder.encode(val); + final CachedData cdHashed = evcacheValueTranscoder.encode(val); + final Future future = client.set(hashKey, cdHashed, timeToLive, latch); + if (log.isDebugEnabled() && shouldLog()) log.debug("SET : APP " + _appName + ", Future " + future + " for hashed key : " + evcKey); + } else { + final Future future = client.set(canonicalKey, cd, timeToLive, latch); + if (log.isDebugEnabled() && shouldLog()) log.debug("SET : APP " + _appName + ", Future " + future + " for key : " + evcKey); } - final Future future = client.set(hashKey == null ? canonicalKey : hashKey, cd, timeToLive, latch); - if (log.isDebugEnabled() && shouldLog()) - log.debug("SET : APP " + _appName + ", Future " + future + " for key : " + evcKey); } if (event != null) { event.setTTL(timeToLive);