obscache: distinct 'clear' and 'reset'
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 09 May 2017 19:02:04 +0200
changeset 2333 adf114c767ab
parent 2332 77c184c80e3e
child 2334 b31ef65a846a
obscache: distinct 'clear' and 'reset' We make a difference between basic invalidatiton (or lack of loading) and 'reset' (current cache data are invalid). We can now ensure a non-None key when we start the update. This will allow us to "update" the existing key instead of recomputing one from scratch. This is more efficient and less racy.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Thu May 04 21:24:02 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Tue May 09 19:02:04 2017 +0200
@@ -243,9 +243,9 @@
         Make sure the cache has been updated to match the repository content before using it"""
         return self._data[rev]
 
-    def clear(self):
+    def clear(self, reset=False):
         """invalidate the cache content"""
-        self._cachekey = None
+        self._cachekey = emptykey if reset else None
         self._data = bytearray()
 
     def uptodate(self, repo):
@@ -261,8 +261,8 @@
             self.load(repo)
 
         valid, startrev, startidx = upgradeneeded(repo, self._cachekey)
-        if not valid:
-            self.clear()
+        if not valid or self._cachekey is None:
+            self.clear(reset=True)
 
         if startrev is None and startidx is None:
             return