Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Contributors
- John Bergvall , `johnbergvall@github <https://github.com/johnbergvall>`_
- AllinolCP, `AllinolCP@github <https://github.com/AllinolCP>`_
- uncle-lv, `uncle-lv@github <https://github.com/uncle-lv>`_
- Vitaliy, `vitalivo@github <https://github.com/vitalivo>`_
2 changes: 1 addition & 1 deletion src/cacheout/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def set_many(self, items: t.Mapping, ttl: t.Optional[T_TTL] = None) -> None:

def _set_many(self, items: t.Mapping, ttl: t.Optional[T_TTL] = None) -> None:
for key, value in items.items():
self._set(key, value, ttl=ttl)
self.set(key, value, ttl=ttl)

def delete(self, key: t.Hashable) -> int:
"""
Expand Down
19 changes: 19 additions & 0 deletions tests/test_lfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,22 @@ def test_lfu_access_count_using_default_callable():

assert value is False
assert cache._access_counts["a"] == -1


def test_lfu_set_many_respects_maxsize():
cache = LFUCache(maxsize=2)
cache.set_many({"a": 1, "b": 2, "c": 3})
assert list(cache.keys()) == ["b", "c"]
assert cache.popitem() == ("b", 2)
assert cache.popitem() == ("c", 3)


def test_lfu_set_many_preserves_eviction_order():
cache = LFUCache(maxsize=2)
cache.set("hot", 1)
cache.get("hot")
cache.set_many({"cold": 2})
cache.set("next", 3)
assert "hot" in cache
assert "cold" not in cache
assert "next" in cache
Loading