[PATCH 1 of 3] lrucachedict: implement clear()
Siddharth Agarwal
sid0 at fb.com
Fri Sep 6 16:01:17 CDT 2013
# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1378498581 25200
# Fri Sep 06 13:16:21 2013 -0700
# Node ID 07a887829c39ae6c929e296af52f03e159a768f1
# Parent c11bcb87c9338b29a67fc6e260d50b9a18705994
lrucachedict: implement clear()
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -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 = {}
diff --git a/tests/test-lrucachedict.py b/tests/test-lrucachedict.py
--- a/tests/test-lrucachedict.py
+++ b/tests/test-lrucachedict.py
@@ -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()
diff --git a/tests/test-lrucachedict.py.out b/tests/test-lrucachedict.py.out
--- a/tests/test-lrucachedict.py.out
+++ b/tests/test-lrucachedict.py.out
@@ -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
More information about the Mercurial-devel
mailing list