mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
Merge bd5b2847ec into aeede53112
This commit is contained in:
commit
03846ab5bc
2 changed files with 12 additions and 1 deletions
|
|
@ -62,7 +62,7 @@ class InMemoryCache(BaseCache):
|
|||
try:
|
||||
# Fast path for common primitive types that are typically small
|
||||
if (
|
||||
isinstance(value, (bool, int, float, str))
|
||||
isinstance(value, (bool, int, float))
|
||||
and len(str(value)) < self.max_size_per_item * MAX_SIZE_PER_ITEM_IN_MEMORY_CACHE_IN_KB
|
||||
): # Conservative estimate
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -392,3 +392,14 @@ async def test_async_increment_pipeline_keeps_each_key_for_its_own_ttl() -> None
|
|||
|
||||
assert cache.get_cache("minute") is None
|
||||
assert cache.get_cache("day") == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("character", ("Ā", "界", "😀"))
|
||||
def test_cache_rejects_unicode_strings_exceeding_the_byte_limit(character: str) -> None:
|
||||
cache: Final = InMemoryCache(max_size_per_item=1, clock=lambda: 100.0)
|
||||
oversized: Final = character * 700
|
||||
assert sys.getsizeof(oversized) > 1024
|
||||
cache.set_cache("large", oversized)
|
||||
assert cache.get_cache("large") is None
|
||||
cache.set_cache("small", character * 10)
|
||||
assert cache.get_cache("small") == character * 10
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue