LRU cache throws KeyError on add()
MrCreosote opened this issue · comments
MrCreosote commented
Might be fixed by 937d2df, but thought I'd report just in case. Follow on issue from #4.
In [1]: import cacheout
In [2]: c = cacheout.LRUCache()
In [3]: c.add('foo', 'bar')
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-3-09536a570d71> in <module>()
----> 1 c.add('foo', 'bar')
~/anaconda3/lib/python3.6/site-packages/cacheout/cache.py in add(self, key, value, ttl)
271 """
272 with self._lock:
--> 273 self._add(key, value, ttl=ttl)
274
275 def _add(self, key, value, ttl=None):
~/anaconda3/lib/python3.6/site-packages/cacheout/cache.py in _add(self, key, value, ttl)
274
275 def _add(self, key, value, ttl=None):
--> 276 if self._has(key):
277 return
278 self._set(key, value, ttl=ttl)
~/anaconda3/lib/python3.6/site-packages/cacheout/cache.py in _has(self, key)
181 def _has(self, key):
182 # Use get method since it will take care of evicting expired keys.
--> 183 return self._get(key, default=_NOTSET) is not _NOTSET
184
185 def size(self):
~/anaconda3/lib/python3.6/site-packages/cacheout/lru.py in _get(self, key, default)
14 def _get(self, key, default=None):
15 value = super()._get(key, default=default)
---> 16 self._cache.move_to_end(key)
17 return value
KeyError: 'foo'
MrCreosote commented
Confirmed fixed in 0.10.2