Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

cache blogposts for 24 hours react native

const cacheIntervaInHours = 24
const cacheExpiryTime = new Date()
cacheExpiryTime.setHours(cacheExpiryTime.getHours() + cacheIntervalInHours)
const lastRequest = await AsyncStorage.getItem("lastRequest")

if (lastRequest == null || lastRequest > cacheExpiryTime) {
        fetch(`${apiUrl}/blogPosts/recent`)
        .then(async (response) => {
            return await response.json()
        })
        .then(async (json) => {
             if (!json || json.length == 0) {
                 throw new Error()
             }
            AsyncStorage.setItem("lastRequest", new Date());
            return await AsyncStorage.setItem('blogPosts', JSON.stringify(json))
        })
        .catch(error => {
            console.error(error)
        })
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular select option default value ngfor 
Javascript :: change class on resize window jquery 
Javascript :: map and get last child in js 
Javascript :: binary conversion recursion in javascript 
Javascript :: nodejs post req accept form data 
Javascript :: tekenaja 
Javascript :: how to change default browser in vs code json 
Javascript :: function expession js 
Javascript :: get output dir from webpack options 
Javascript :: setinterval clearinterval querySelector until render 
Javascript :: add and remove multiple markers on google maps js 
Javascript :: JavaScript detect card type 
Javascript :: build an javascript URL and its search parameters 
Javascript :: Example code of using inner blocks in Wordpress with ES5 
Javascript :: javascript extrsct object 
Javascript :: ajax:drop-down remove an d add select option 
Javascript :: url is not a constructor javascript 
Javascript :: tampermonkey all pages 
Javascript :: same onclick function on different elements and change another element 
Javascript :: icon with label in react native 
Javascript :: if there is an invalid expression in eval js then how to get ti 
Javascript :: this 
Javascript :: clasp enable oauthScopes appsscript.json 
Javascript :: react Fractional rating 
Javascript :: node middle code for server 
Javascript :: diable input javascript 
Javascript :: summernote click event jquery 
Javascript :: browser app get screen siwe 
Javascript :: how to save js object to clipboard 
Javascript :: a complex label expression before a colon must be parenthesized 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =