def __init__(self, size_limit=100, weak_type='value'):
"""
Parameters
----------
size_limit : int
integer that defines the size of the LRU cache. Default is 100.
"""
super(WeakLRUCache, self).__init__()
self._size_limit = size_limit
self.weak_type = weak_type
if weak_type == 'value':
self._weak_cache = weakref.WeakValueDictionary()
elif weak_type == 'key':
self._weak_cache = weakref.WeakKeyDictionary()
else:
raise ValueError("weak_type must be either 'key' or 'value'")
self._cache = OrderedDict()
评论列表
文章目录