mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-28 04:04:31 +00:00
Add tests for cache with TTL
This commit is contained in:
parent
f0a9f8c61e
commit
bac6f41eb7
1 changed files with 33 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
@ -344,7 +345,7 @@ def test_custom_redis_cache_with_key():
|
||||||
pytest.fail(f"Error occurred:")
|
pytest.fail(f"Error occurred:")
|
||||||
litellm.cache = None
|
litellm.cache = None
|
||||||
|
|
||||||
test_custom_redis_cache_with_key()
|
# test_custom_redis_cache_with_key()
|
||||||
|
|
||||||
def test_hosted_cache():
|
def test_hosted_cache():
|
||||||
litellm.cache = Cache(type="hosted") # use api.litellm.ai for caching
|
litellm.cache = Cache(type="hosted") # use api.litellm.ai for caching
|
||||||
|
@ -364,3 +365,20 @@ def test_hosted_cache():
|
||||||
|
|
||||||
# test_hosted_cache()
|
# test_hosted_cache()
|
||||||
|
|
||||||
|
|
||||||
|
def test_redis_cache_with_ttl():
|
||||||
|
cache = Cache(type="redis", host=os.environ['REDIS_HOST'], port=os.environ['REDIS_PORT'], password=os.environ['REDIS_PASSWORD'])
|
||||||
|
cache.add_cache(cache_key="test_key", result="test_value", ttl=1)
|
||||||
|
cached_value = cache.get_cache(cache_key="test_key")
|
||||||
|
assert cached_value == "test_value"
|
||||||
|
time.sleep(2)
|
||||||
|
assert cache.get_cache(cache_key="test_key") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_in_memory_cache_with_ttl():
|
||||||
|
cache = Cache(type="local")
|
||||||
|
cache.add_cache(cache_key="test_key", result="test_value", ttl=1)
|
||||||
|
cached_value = cache.get_cache(cache_key="test_key")
|
||||||
|
assert cached_value == "test_value"
|
||||||
|
time.sleep(2)
|
||||||
|
assert cache.get_cache(cache_key="test_key") is None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue