changeset 19710:887ffa22fd0d

lrucachedict: implement clear()
author Siddharth Agarwal <sid0@fb.com>
date Fri, 06 Sep 2013 13:16:21 -0700
parents 600ea1a6884c
children 0a881ea4bed4
files mercurial/util.py tests/test-lrucachedict.py tests/test-lrucachedict.py.out
diffstat 3 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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