2

I use axios in my React-Native app

first , configure the headers

function configHeaders()
{
    // I tested all these below 3 lines , no on worked
    axios.defaults.headers.common["Pragma"] = "no-cache";
    axios.defaults.headers.common["Cache-Control"] = "no-cache";
    axios.defaults.headers.common["Cache-Control"] = "no-store";
}

the data returned from the below request is old data , not the current data in my database

exports.getInfo = async function ()
{
    configHeaders();
    return await cachios.get(URL + '/user/info').then(data => {
        return { success : true , data : data.data.data.user };
    }).catch(err => {
        return { success : false , message : err.response.data.message };
    });
}
27mdmo7sn
  • 53
  • 1
  • 6

1 Answers1

2

You can try to add cache buster in the URL - forcing each request to consider as new:

const cacheBuster = (url) => `${url}?cb=${Date.now()}`;
exports.getInfo = async function ()
{
    configHeaders();
    return await cachios.get(cacheBuster(URL + '/user/info')).then(data => {
        return { success : true , data : data.data.data.user };
    }).catch(err => {
        return { success : false , message : err.response.data.message };
    });
}
Adidi
  • 5,097
  • 4
  • 23
  • 30