mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-20 21:27:32 +00:00
lrucache: use explicit sentinel instead of None
just in case someone wants to cache a big pile of nothing
This commit is contained in:
parent
2766693706
commit
b2a4ae6bc2
1 changed files with 6 additions and 3 deletions
|
@ -1,3 +1,6 @@
|
|||
sentinel = object()
|
||||
|
||||
|
||||
class LRUCache:
|
||||
def __init__(self, capacity, dispose):
|
||||
self._cache = {}
|
||||
|
@ -29,9 +32,9 @@ def __contains__(self, key):
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue