Skip to content

Commit

Permalink
cache control support in s3 uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Jun 30, 2024
1 parent 07b4ae5 commit d62e15e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/adapters/aws_s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Any

from app import settings
from app import state
Expand All @@ -21,12 +22,22 @@ async def get_object_data(key: str) -> bytes | None:
return await s3_object["Body"].read()


async def save_object_data(key: str, data: bytes) -> None:
async def save_object_data(
key: str,
data: bytes,
*,
max_age: int | None = None,
) -> None:
try:
params: dict[str, Any] = {}
if max_age is not None:
params["CacheControl"] = f"max-age={max_age}"

await state.s3_client.put_object(
Bucket=settings.AWS_S3_BUCKET_NAME,
Key=key,
Body=data,
**params,
)
except Exception:
logging.warning(
Expand Down

0 comments on commit d62e15e

Please sign in to comment.