2015-07-23 33 views
14

Sto costruendo un'applicazione in risposta nativa che effettua chiamate di recupero che si basano sulle informazioni più aggiornate dal server. Ho notato che sembra memorizzare nella cache la risposta e se eseguo quella chiamata di recupero di nuovo restituisce la risposta memorizzata nella cache piuttosto che le nuove informazioni dal mio server.React Native - Recupera chiamata cache

La mia funzione è la seguente:

goToAll() { 
    AsyncStorage.getItem('FBId') 
    .then((value) => { 
     api.loadCurrentUser(value) 
     .then((res) => { 
      api.loadContent(res['RegisteredUser']['id']) 
      .then((res2) => { 
       console.log(res2); 
       this.props.navigator.push({ 
       component: ContentList, 
       title: 'All', 
       passProps: { 
       content: res2, 
      user: res['RegisteredUser']['id'] 
      } 
     }) 
     }); 
    }); 
    }) 
    .catch((error) => {console.log(error);}) 
    .done(); 
} 

e la funzione da api.js im chiamata è la seguente:

loadContent(userid){ 
    let url = `http://####.com/api/loadContent?User_id=${userid}`; 
    return fetch(url).then((response) => response.json()); 
} 

risposta

26

È possibile impostare una Header per evitare che la richiesta vada in cache. Esempio di seguito:

return fetch(url, { 
    headers: { 
    'Cache-Control': 'no-cache' 
    } 
}).then(function (res) { 
    return res.json(); 
}).catch(function(error) { 
    console.warn('Request Failed: ', error); 
});