lrucachedict: implement clear()

This commit is contained in:
Siddharth Agarwal 2013-09-06 13:16:21 -07:00
parent 6e9f30dc4d
commit 26051a2eee
3 changed files with 12 additions and 0 deletions

View File

@ -242,6 +242,10 @@ class lrucachedict(object):
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 = {}

View File

@ -31,5 +31,8 @@ def test_lrucachedict():
d['f'] = 'vf'
printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
d.clear()
printifpresent(d, ['b', 'c', 'd', 'e', 'f'])
if __name__ == '__main__':
test_lrucachedict()

View File

@ -24,3 +24,8 @@ d['d']: vd
'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