"react-native-sync-localstorage expire date" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "react-native-sync-localstorage expire date" answered properly. Developers are finding an appropriate answer about react-native-sync-localstorage expire date related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like react-native-sync-localstorage expire date. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on react-native-sync-localstorage expire date.
react-native-sync-localstorage expire date
/**
*
* @param urlAsKey
* @param expireInMinutes
* @returns {Promise.<*>}
*/
async getCachedUrlContent(urlAsKey, expireInMinutes = 60) {
let data = null;
await AsyncStorage.getItem(urlAsKey, async (err, value) => {
data = (JSON.parse(value));
// there is data in cache && cache is expired
if (data !== null && data['expireAt'] &&
new Date(data.expireAt) < (new Date())) {
//clear cache
AsyncStorage.removeItem(urlAsKey);
//update res to be null
data = null;
} else {
console.log('read data from cache ');
}
});
//update cache + set expire at date
if (data === null) {
console.log('cache new Date ');
//fetch data
data = fetch(urlAsKey).then((response) => response.json())
.then(apiRes => {
//set expire at
apiRes.expireAt = this.getExpireDate(expireInMinutes);
//stringify object
const objectToStore = JSON.stringify(apiRes);
//store object
AsyncStorage.setItem(urlAsKey, objectToStore);
console.log(apiRes.expireAt);
return apiRes;
});
}
return data;
},
/**
*
* @param expireInMinutes
* @returns {Date}
*/
getExpireDate(expireInMinutes) {
const now = new Date();
let expireTime = new Date(now);
expireTime.setMinutes(now.getMinutes() + expireInMinutes);
return expireTime;
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on react-native-sync-localstorage expire date can get a collection of related answers to their query. Programmers need to enter their query on react-native-sync-localstorage expire date related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about react-native-sync-localstorage expire date for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of react-native-sync-localstorage expire date while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "react-native-sync-localstorage expire date". Visit this developer's friendly online web community, CodeProZone, and get your queries like react-native-sync-localstorage expire date resolved professionally and stay updated to the latest Whatever updates.