dasahcc commented on a change in pull request #367: Add transient cache for 
CustomRestClient implementation
URL: https://github.com/apache/helix/pull/367#discussion_r310212407
 
 

 ##########
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java
 ##########
 @@ -97,7 +106,43 @@ public CustomRestClientImpl(HttpClient httpClient) {
           kv -> result.put(kv.getKey(), 
kv.getValue().get(IS_HEALTHY_FIELD).asBoolean()));
       return result;
     };
-    return handleResponse(post(url, payLoads), jsonConverter);
+    String requestId = baseUrl + customPayloads.toString() + 
partitions.toString();
+    try {
+      lock(requestId);
+      if (_cachedResults.containsKey(requestId)) {
+        return _cachedResults.get(requestId);
+      }
+      Map<String, Boolean> result = handleResponse(post(url, payLoads), 
jsonConverter);
+      _cachedResults.put(requestId, result);
+      return result;
+    } catch (InterruptedException e) {
+      e.printStackTrace();
+    } finally {
+      unlock(requestId);
+    }
+    return Collections.emptyMap();
+  }
+
+  @VisibleForTesting
+  Map<String, Map<String, Boolean>> getCachedResults() {
+    return _cachedResults;
+  }
+
+  private void lock(String key) throws InterruptedException {
+    synchronized (lockedKeys) {
 
 Review comment:
   This is not locking on key level but set object level.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to