Skip to content

Cache behaviour if the original image in S3 is changed #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GraemeBryce-Holibob opened this issue Apr 21, 2025 · 1 comment
Open

Cache behaviour if the original image in S3 is changed #594

GraemeBryce-Holibob opened this issue Apr 21, 2025 · 1 comment
Assignees
Labels

Comments

@GraemeBryce-Holibob
Copy link

What is your question?

I would like to know if I am missing something.

If a user has already called for a given version of an image, say 300x300, CloudFront will cache it and serve it to all users requesting the same variant. This is, of course, the desired behaviour.

However, if an admin updates the image in S3 (with or without versioning on the bucket) then of course the image in the CDN is now "invalid".

Does the solution provide a way in the base64 object or via the queryString to invalidate the cache and ensure that new versions of the image are created when requested?

This does appear challenging to implement for a number reasons:

  • We do not want to make a call to S3 on every request
  • We do not want users to commonly be able to bypass the cache as this defeats one goal of the solution
  • The solution would somehow have to track the relationship between cached variants and the original

Our solution to this is to hold an assetId in our product catalog that is independant of the productId and thus if a new image is uploaded then a new object is loaded to S3 and all is well.

@gsingh04
Copy link
Member

gsingh04 commented Apr 21, 2025

@GraemeBryce-Holibob please take a look at #285, it has explanation of how the caching currently works in the solution and how you can make changes to it i.e through cache policy on CloudFront and through cache-control headers on objects in S3.

Additionally, you can also explore image request expiration which was added in response to #349

// If expires query param is included, override max caching age

Let us know which workflow meets your requirements and we can revisit this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants