diff --git a/tests/test_utils.py b/tests/test_utils.py index b7472413..031e086f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -29,6 +29,14 @@ def test_lru_cache_set_multiple(): assert cache.lru == ["a"] +def test_lru_cache_set_update(): + cache = LRUCache(capacity=3) + cache["a"] = 1 + cache["a"] = 2 + + assert cache["a"] == 2 + + def test_lru_cache_get(): cache = LRUCache(capacity=3) cache["a"] = 1 diff --git a/tinydb/utils.py b/tinydb/utils.py index 08430ba1..e1f01fbc 100644 --- a/tinydb/utils.py +++ b/tinydb/utils.py @@ -99,8 +99,8 @@ def get(self, key: K, default: Optional[D] = None) -> Optional[Union[V, D]]: def set(self, key: K, value: V): if self.cache.get(key): + self.cache[key] = value self.cache.move_to_end(key, last=True) - else: self.cache[key] = value