Skip to content

Commit eb7e9fe

Browse files
committed
[minor change] Avoid creating same CacheKey twice
1 parent 6ffdcba commit eb7e9fe

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/main/java/redis/clients/jedis/csc/CacheConnection.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,23 @@ public void disconnect() {
6262

6363
@Override
6464
public <T> T executeCommand(final CommandObject<T> commandObject) {
65-
CacheKey key = new CacheKey<>(commandObject);
66-
if (!clientSideCache.isCacheable(key)) {
65+
final CacheKey cacheKey = new CacheKey(commandObject);
66+
if (!clientSideCache.isCacheable(cacheKey)) {
6767
clientSideCache.getStats().nonCacheable();
6868
return super.executeCommand(commandObject);
6969
}
7070

71-
final CacheKey cacheKey = new CacheKey(commandObject);
7271
CacheEntry<T> cacheEntry = clientSideCache.get(cacheKey);
73-
74-
// CACHE HIT !!
75-
if (cacheEntry != null) {
72+
if (cacheEntry != null) { // (probable) CACHE HIT !!
7673
cacheEntry = validateEntry(cacheEntry);
7774
if (cacheEntry != null) {
75+
// CACHE HIT confirmed !!!
7876
clientSideCache.getStats().hit();
79-
return (T) cacheEntry.getValue();
77+
return cacheEntry.getValue();
8078
}
8179
}
8280

83-
// CACHE MISS!!
81+
// CACHE MISS !!
8482
clientSideCache.getStats().miss();
8583
T value = super.executeCommand(commandObject);
8684
if (value != null) {

0 commit comments

Comments
 (0)