lrucache: use explicit sentinel instead of None

just in case someone wants to cache a big pile of nothing
This commit is contained in:
Marian Beermann 2017-06-16 00:41:38 +02:00
parent 2766693706
commit b2a4ae6bc2
1 changed files with 6 additions and 3 deletions

View File

@ -1,3 +1,6 @@
sentinel = object()
class LRUCache:
def __init__(self, capacity, dispose):
self._cache = {}
@ -29,9 +32,9 @@ class LRUCache:
return key in self._cache
def get(self, key, default=None):
value = self._cache.get(key, default)
if value is default:
return value
value = self._cache.get(key, sentinel)
if value is sentinel:
return default
self._lru.remove(key)
self._lru.append(key)
return value