Skip to content

fix(storage): s3 based images not using browser cache - #151

Open
thezak48 wants to merge 4 commits into
developfrom
fix/s3-cache
Open

fix(storage): s3 based images not using browser cache#151
thezak48 wants to merge 4 commits into
developfrom
fix/s3-cache

Conversation

@thezak48

Copy link
Copy Markdown
Owner

This pull request adds an in-memory caching layer for S3 presigned URLs in storage.py to improve performance and reduce unnecessary S3 calls. The cache is thread-safe, supports eviction on asset changes, and ensures URLs are refreshed before expiration. The main changes are grouped below:

Presigned URL Caching:

  • Introduced a thread-safe in-memory cache (_presigned_url_cache) for S3 presigned URLs, including logic to store, retrieve, and evict cached URLs with expiration handling. [1] [2] [3]
  • Updated get_presigned_image_url to use the cache, returning a cached URL if available and valid, and caching new URLs after generation.

Cache Invalidation:

  • Added cache eviction logic in save_upload_file and delete_comparison_assets to ensure the cache remains consistent when assets are added or deleted. [1] [2]

Copilot AI review requested due to automatic review settings July 12, 2026 11:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a per-process, thread-safe in-memory cache for S3 presigned image URLs in storage.py, aiming to reduce repeated S3 calls and keep redirect URLs stable within their TTL.

Changes:

  • Added a global presigned-URL cache with locking and expiry handling.
  • Updated get_presigned_image_url() to return cached URLs when still valid and cache newly generated URLs.
  • Evicted cached entries when uploads overwrite assets or when comparison assets are deleted.

Comment thread storage.py
Comment thread storage.py
@thezak48
thezak48 force-pushed the fix/s3-cache branch 2 times, most recently from f96103e to 5dda750 Compare July 12, 2026 11:10
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants