diff --git a/litellm/caching.py b/litellm/caching.py index 67d57b6e8..f63df9464 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -156,6 +156,7 @@ class S3Cache(BaseCache): # Convert value to JSON before storing in S3 serialized_value = str(value) if ttl is not None: + cache_control = f"immutable, max-age={ttl}, s-maxage={ttl}" import datetime # Calculate expiration time @@ -167,11 +168,22 @@ class S3Cache(BaseCache): Key=key, Body=serialized_value, Expires=expiration_time, + CacheControl=cache_control, + ContentType="application/json", + ContentLanguage="en", + ContentDisposition=f"inline; filename=\"{key}.json\"" ) else: + cache_control = "immutable, max-age=31536000, s-maxage=31536000" # Upload the data to S3 without specifying Expires self.s3_client.put_object( - Bucket=self.bucket_name, Key=key, Body=serialized_value + Bucket=self.bucket_name, + Key=key, + Body=serialized_value, + CacheControl=cache_control, + ContentType="application/json", + ContentLanguage="en", + ContentDisposition=f"inline; filename=\"{key}.json\"" ) except Exception as e: # NON blocking - notify users S3 is throwing an exception