Patchwork [1,of,3] lrucachedict: implement clear()

login
register
mail settings
Submitter Siddharth Agarwal
Date Sept. 6, 2013, 9:01 p.m.
Message ID <07a887829c39ae6c929e.1378501277@dev1091.prn1.facebook.com>
Download mbox | patch
Permalink /patch/2395/
State Accepted
Commit 887ffa22fd0de2d749392f32a1171713e5fc94d6
Headers show

Comments

Siddharth Agarwal - Sept. 6, 2013, 9:01 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1378498581 25200
#      Fri Sep 06 13:16:21 2013 -0700
# Node ID 07a887829c39ae6c929e296af52f03e159a768f1
# Parent  c11bcb87c9338b29a67fc6e260d50b9a18705994
lrucachedict: implement clear()

Patch

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