Skip to content

Commit

Permalink
fix to correctly fetch metadata for s3 object
Browse files Browse the repository at this point in the history
  • Loading branch information
philbo committed Feb 17, 2025
1 parent f97d66b commit addedbf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hishel/_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ def remove_expired(self, ttl: int, key: str) -> None:
if not obj["Key"].startswith("hishel-"): # pragma: no cover
continue

if get_timestamp_in_ms() - float(obj["Metadata"]["created_at"]) > ttl:
try:
metadata_obj = self._client.head_object(Bucket=self._bucket_name, Key=obj["Key"]).get("Metadata", {})
except ClientError as e:
if e.response["Error"]["Code"] == "404":
continue

if not metadata_obj or "created_at" not in metadata_obj:
continue

if get_timestamp_in_ms() - float(metadata_obj["created_at"]) > ttl:
self._client.delete_object(Bucket=self._bucket_name, Key=obj["Key"])

def remove_entry(self, key: str) -> None:
Expand Down

0 comments on commit addedbf

Please sign in to comment.