caching - React Native - Fetch call cached -
i building app in react native makes fetch calls rely on date information server. have noticed seems cache response , if run fetch call again returns cached response rather new information server.
my function follows:
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(); }
and function api.js im calling follows:
loadcontent(userid){ let url = `http://####.com/api/loadcontent?user_id=${userid}`; return fetch(url).then((response) => response.json()); }
you can set header
prevent request being cached. example below:
return fetch(url, { headers: { 'cache-control': 'no-cache' } }).then(function (res) { return res.json(); }).catch(function(error) { console.warn('request failed: ', error); });
Comments
Post a Comment