lrucachedict: implement clear()
authorSiddharth Agarwal <sid0@fb.com>
Fri, 06 Sep 2013 13:16:21 -0700
changeset 19710 887ffa22fd0d
parent 19709 600ea1a6884c
child 19711 0a881ea4bed4
lrucachedict: implement clear()
mercurial/util.py
tests/test-lrucachedict.py
tests/test-lrucachedict.py.out
--- a/mercurial/util.py	Sat Sep 07 16:08:11 2013 -0500
+++ b/mercurial/util.py	Fri Sep 06 13:16:21 2013 -0700
@@ -242,6 +242,10 @@
     def __contains__(self, key):
         return key in self._cache
 
+    def clear(self):
+        self._cache.clear()
+        self._order = deque()
+
 def lrucachefunc(func):
     '''cache most recent results of function calls'''
     cache = {}
--- a/tests/test-lrucachedict.py	Sat Sep 07 16:08:11 2013 -0500
+++ b/tests/test-lrucachedict.py	Fri Sep 06 13:16:21 2013 -0700
@@ -31,5 +31,8 @@
     d['f'] = 'vf'
     printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
 
+    d.clear()
+    printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
+
 if __name__ == '__main__':
     test_lrucachedict()
--- a/tests/test-lrucachedict.py.out	Sat Sep 07 16:08:11 2013 -0500
+++ b/tests/test-lrucachedict.py.out	Fri Sep 06 13:16:21 2013 -0700
@@ -24,3 +24,8 @@
 'e' in d: False
 'f' in d: True
 d['f']: vf
+'b' in d: False
+'c' in d: False
+'d' in d: False
+'e' in d: False
+'f' in d: False