mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(cache): preserve non-JSON container entries
This commit is contained in:
parent
5daa555bb0
commit
785ae73276
2 changed files with 13 additions and 1 deletions
|
|
@ -73,7 +73,10 @@ class InMemoryCache(BaseCache):
|
|||
|
||||
# Only convert to JSON if absolutely necessary
|
||||
if not isinstance(value, (str, bytes)):
|
||||
value = json.dumps(value, default=str)
|
||||
try:
|
||||
value = json.dumps(value, default=str)
|
||||
except (TypeError, ValueError):
|
||||
value = repr(value)
|
||||
|
||||
return sys.getsizeof(value) / 1024 <= self.max_size_per_item
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,15 @@ def test_in_memory_cache_max_size_per_item_measures_container_contents():
|
|||
assert in_memory_cache.get_cache(key="small") == small_value
|
||||
|
||||
|
||||
def test_in_memory_cache_accepts_small_container_with_non_json_keys():
|
||||
in_memory_cache = InMemoryCache(max_size_per_item=1)
|
||||
value = {("key", "key-hash"): ("job-1",)}
|
||||
|
||||
in_memory_cache.set_cache(key="active-jobs", value=value)
|
||||
|
||||
assert in_memory_cache.get_cache(key="active-jobs") == value
|
||||
|
||||
|
||||
def test_in_memory_cache_ttl():
|
||||
"""
|
||||
Check that
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue