Skip to content

Commit 61c2f5a

Browse files
Reset cache ttl when no arg is passed (#181)
This PR resets the cache entry TTL to infinite/no expiration if we call `set_ttl()` with no arguments. Otherwise once a TTL is set, it can only be changed to another integer.
1 parent 2162c03 commit 61c2f5a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

redisvl/extensions/llmcache/base.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def set_ttl(self, ttl: Optional[int] = None):
2828
if not isinstance(ttl, int):
2929
raise ValueError(f"TTL must be an integer value, got {ttl}")
3030
self._ttl = int(ttl)
31+
else:
32+
self._ttl = None
3133

3234
def clear(self) -> None:
3335
"""Clear the LLMCache of all keys in the index."""

tests/integration/test_llmcache.py

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def test_set_ttl(cache):
7070
assert cache.ttl == 5
7171

7272

73+
def test_reset_ttl(cache):
74+
cache.set_ttl(4)
75+
cache.set_ttl()
76+
assert cache.ttl is None
77+
78+
7379
# Test basic store and check functionality
7480
def test_store_and_check(cache, vectorizer):
7581
prompt = "This is a test prompt."

0 commit comments

Comments
 (0)