Nitin Uprety
Nitin Uprety

Reputation: 1

IE 11 issue - automatically cache responses from GET requests - Reactjs

I'm making a GET request to a web service for AJAX call. Internet Explorer, is doing automatically cache responses from GET requests.

This is the code,

export function fetchReportSet () {
  return function(dispatch) {
       axios.get(`${ROOT_URL}/api/reports/`, {
         headers: {Pragma: 'no-cache'},
         headers: {Authorization:'Token '+ localStorage.getItem('token')}
       })
           .then(response => {
             dispatch({type: FETCH_REPORT , payload: response.data});
           })
           .catch(() => {
           });
  }
}

Any help will be appreciated.

Upvotes: 0

Views: 2691

Answers (2)

this help me

axios.defaults.headers.get['Pragma'] = 'no-cache';

axios.defaults.headers.get['Cache-Control'] = 'no-cache, no-store';

Upvotes: 1

Zhi Lv
Zhi Lv

Reputation: 21516

Try to refer to this thread to add a timestamp in the url, or refer to this article to add the Cache-Control: no-cache header set.

Code like this:

import axios from 'axios';
import { cacheAdapterEnhancer } from 'axios-extensions';

const http = axios.create({
    baseURL: '/',
    headers: { 'Cache-Control': 'no-cache' },
    // cache will be enabled by default
    adapter: cacheAdapterEnhancer(axios.defaults.adapter)
});

http.get('/users'); // make real http request

Upvotes: 1

Related Questions