From c54e0813b444f6098230685d6d855eebe0f8bf20 Mon Sep 17 00:00:00 2001 From: David Manouchehri Date: Wed, 3 Jan 2024 13:44:28 -0500 Subject: [PATCH 1/2] (caching) improve s3 backend by specifying cache-control and content-type --- litellm/caching.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/litellm/caching.py b/litellm/caching.py index 0b1e18e46..200c696d5 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -155,6 +155,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 @@ -166,11 +167,18 @@ class S3Cache(BaseCache): Key=key, Body=serialized_value, Expires=expiration_time, + CacheControl=cache_control, + ContentType="application/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" ) except Exception as e: # NON blocking - notify users S3 is throwing an exception From 56b03732ae961be4547d07005fed38b4e73837f5 Mon Sep 17 00:00:00 2001 From: David Manouchehri Date: Sun, 7 Jan 2024 12:21:15 -0500 Subject: [PATCH 2/2] (caching) Set Content-Disposition header and Content-Language --- litellm/caching.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/caching.py b/litellm/caching.py index 200c696d5..018a2f87d 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -168,7 +168,9 @@ class S3Cache(BaseCache): Body=serialized_value, Expires=expiration_time, CacheControl=cache_control, - ContentType="application/json" + ContentType="application/json", + ContentLanguage="en", + ContentDisposition=f"inline; filename=\"{key}.json\"" ) else: cache_control = "immutable, max-age=31536000, s-maxage=31536000" @@ -178,7 +180,9 @@ class S3Cache(BaseCache): Key=key, Body=serialized_value, CacheControl=cache_control, - ContentType="application/json" + ContentType="application/json", + ContentLanguage="en", + ContentDisposition=f"inline; filename=\"{key}.json\"" ) except Exception as e: # NON blocking - notify users S3 is throwing an exception