Как заставить ax ios не кэшироваться в GET-запросах - PullRequest
0 голосов
/ 15 апреля 2020

Я использую топор ios в моем приложении React-Native.

. Сначала настройте заголовки

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";
}

. Данные, возвращаемые из запроса ниже, являются старыми, а не текущими данными. в моей базе

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 };
    });
}

1 Ответ

0 голосов
/ 15 апреля 2020

Вы можете попробовать добавить кеш-бустер в URL - заставляя каждый запрос считать новым:

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 };
    });
}
...