https://pantsbuild.org/ logo
#development
Title
# development
f

full-kilobyte-93429

03/18/2016, 10:29 PM
this is a small hack to get hit rate back to close 100%
Copy code
def get(self, step_request):
     """Get the cached StepResult for a given StepRequest."""
-    result_key = self._storage.get_mapping(self._storage.put(step_request))
+    result_key = self._storage.get_mapping(self._compute_key(step_request))
     if result_key is None:
       self._cache_stats.add_miss()
       return None
@@ -270,7 +271,7 @@ class Cache(Closable):
 
   def put(self, step_request, step_result):
     """Save the StepResult for a given StepResult."""
-    request_key = self._storage.put(step_request)
+    request_key = self._compute_key(step_request)
     result_key = self._storage.put(step_result)
     return self._storage.add_mapping(from_key=request_key, to_key=result_key)
 
@@ -291,6 +292,13 @@ class Cache(Closable):
   def close(self):
     self._storage.close()
 
+  def _compute_key(self, step_request):
+    # We want to exclude step_id from step_request but named tuple is immutable,
+    # so make a copy and reset its step_id field.
+    step_request_copy = step_request._replace(step_id=0)
+    key = self._storage.put(step_request_copy)
+    return key