Storage.get( { download: true } ) does not get latest version of S3 bucket file after modifying
See original GitHub issueUnsure if this is a bug, but encountered some weird caching behaviour with Storage.get() when retrieving file data contents, so this should be clarified. I have an Amplify project that gets data from a text file stored in an S3 bucket made with initializing Amplify storage. The issue is when recent updates are made on a specific file, like updating the file directly on the management console or calling Storage.put(), Calling Storage.get() with { download: true } to get the file contents will still retrieve the unmodified version of the file, and not the latest version; this issue persists for some short period of time until get() eventually retrieves the latest. I see that the changes are reflected in the metadata of the file when I call Storage.list(), so I am not sure why Storage.get does not get the changed file immediately. I doubt if this is expected behaviour, why does this happen? Any way to resolve this issue?
Project was initialized with amplify init and S3 storage resources were made by calling amplify add storage.
A short example of how I use Storage.get():
Storage.get('file-name', { download: true }) .then(data => { data.Body.text().then(string => { // handle the String data return String }); }) .catch(e => { // handle error });
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top GitHub Comments
Same as #7095
By default, the HTTP Headers returned by S3 looks something like follows:
Note there is no
Cache-Control
orExpires
headers. When those headers are missing ANDLast-Modified
header is present, browsers calculates what’s called Heuristic freshness and sets its own ttl in cache. e.g. Firefox docsThis results in subsequent requests getting cached by default as seen:
As Harry mentioned in https://github.com/aws-amplify/amplify-js/issues/7095#issuecomment-728355794 Doing something like
will get S3 to return the appropriate
Cache-Control
headers which eliminates this issue.Similar issue (that’s also unresolved) here: #6413