aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.12k forks source link

Storage.get() serves requests from Disk cache #8566

Closed anjanvb closed 3 years ago

anjanvb commented 3 years ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Storage

Amplify Categories

storage

Environment information

``` # Put output below this line System: OS: macOS 10.15.7 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 133.17 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 14.7.0 - /usr/local/bin/node npm: 6.14.7 - /usr/local/bin/npm Browsers: Chrome: 91.0.4472.114 Firefox: 78.10.1 Safari: 14.1.1 npmPackages: @aws-amplify/api: ^3.2.29 => 3.3.0 (4.0.4) @aws-amplify/auth: ^3.4.29 => 3.4.31 (4.1.0) @aws-amplify/core: ^3.8.21 => 3.8.23 (4.1.2) @aws-amplify/storage: ^3.3.29 => 3.4.1 (4.2.1) @aws-amplify/ui-react: ^1.2.4 => 1.2.4 @craco/craco: ^6.1.1 => 6.1.2 @loadable/component: ^5.14.1 => 5.14.1 @reduxjs/toolkit: ^1.6.0 => 1.6.0 @reduxjs/toolkit-query: 1.0.0 @reduxjs/toolkit-query-react: 1.0.0 @testing-library/jest-dom: ^5.11.9 => 5.12.0 @testing-library/react: ^11.2.5 => 11.2.6 @testing-library/user-event: ^12.8.3 => 12.8.3 @uiw/react-md-editor: ^3.4.7 => 3.4.7 aws-amplify: ^4.1.2 => 4.1.2 axios: ^0.21.1 => 0.21.1 date-fns: ^2.19.0 => 2.21.2 emotion: ^10.0.27 => 10.0.27 html-react-parser: ^1.2.4 => 1.2.6 jwt-decode: ^3.1.2 => 3.1.2 jwt-simple: ^0.5.6 => 0.5.6 node-sass: ^5.0.0 => 5.0.0 password-validator: ^5.1.1 => 5.1.1 react: ^17.0.1 => 17.0.2 react-avatar: ^3.10.0 => 3.10.0 react-dom: ^17.0.1 => 17.0.2 react-h5-audio-player: ^3.6.2 => 3.7.0 react-markdown: ^5.0.3 => 5.0.3 (6.0.2) react-mentions: ^4.1.1 => 4.1.1 react-pdf: ^5.2.0 => 5.2.0 react-player: ^2.9.0 => 2.9.0 react-redux: ^7.2.4 => 7.2.4 react-router: ^5.2.0 => 5.2.0 react-router-dom: ^5.2.0 => 5.2.0 react-scripts: 4.0.3 => 4.0.3 react-sizeme: ^3.0.1 => 3.0.1 redux-devtools-extension: ^2.13.9 => 2.13.9 web-vitals: ^1.1.1 => 1.1.1 webpack-bundle-analyzer: ^4.4.0 => 4.4.1 webpackbar: ^5.0.0-3 => 5.0.0-3 npmGlobalPackages: aws-cdk: 1.95.1 former2: 0.2.53 localtunnel: 2.0.0 npm: 6.14.7 npmrc: 1.1.1 ```

Describe the bug

It looks like Storage.get() continues to serve the content from (disk cache) even with smaller expiry. My use case is pretty simple. I've got a JSON file in a prefix in S3, I need to be able to update the file and read the file from the React app. Since the get request continues to be served from disk cache the application continues to see outdated content.

Screen Shot 2021-07-10 at 10 01 45 AM

I've tried with very large and very small (like 2 seconds) of expires time but the behavior is consistent. Wondering if this is an expected behavior.

Expected behavior

Each call to Storage.get() should return the current (available) content in the S3 bucket.

Reproduction steps

  1. Install @aws-amplify/storage, @aws-amplify/core, @aws-amplify/auth
  2. Setup Cognito user pool and identity pool with appropriate permissions to the S3 bucket.
  3. Put a text/json file in the S3 bucket
  4. Make Storage.get() requests to the file to see the file content
  5. Update the file content in S3
  6. Make Storage.get() call again to get updated content from S3
  7. Notice that Storage.get() continues to serve data from disk cache which is outdated.

Code Snippet


async readFile(key){
        try {
            const result = await Storage.get(key, { contentType: 'text/plain', download: true, expires: 2 });            
             return result.Body.text(); // return .text() promise
        } catch (error) {
            return "";
        }        
 }

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

anjanvb commented 3 years ago

Nevermind. Gotta use cacheControl: 'no-cache'

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.