Add input validation and improve documentation for max_age_days parameter

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-05-05 22:49:01 +00:00
parent 223683d8bd
commit b69e328752

View File

@@ -214,10 +214,27 @@ class LLMResponseCacheStorage:
"""
Removes cache entries older than the specified number of days.
This method helps maintain the cache size and ensures that only recent
responses are kept, which is important for keeping the cache relevant
and preventing it from growing too large over time.
Args:
max_age_days: Maximum age of cache entries in days. Defaults to 7.
If set to 0, all entries will be deleted.
Must be a non-negative integer.
Raises:
ValueError: If max_age_days is not a non-negative integer.
"""
if not isinstance(max_age_days, int) or max_age_days < 0:
error_msg = "max_age_days must be a non-negative integer"
self._printer.print(
content=f"LLM RESPONSE CACHE ERROR: {error_msg}",
color="red",
)
logger.error(error_msg)
raise ValueError(error_msg)
try:
conn = self._get_connection()
cursor = conn.cursor()