Since the cache is empty, we make a request and save the data to the cache exp: (Date.now() + msToExpire) = 17:00 + 30 min = 17:30. And let's imagine that the msToExpire = 30 min. And in the next call of this function you compare exp from your save element with current time Date.now().įor example the cache is empty, and you call getOrSetCache at 17:00. If this element is not in the cache, you make a request and after receive data, you save in to ls, and set time to expire as date.now() + msToExpire. When you call getOrSetCache, you pass msToExpire to arguments. This code works, but I couldn't understand how, is there any other better way to cache with expiration date? Solution My question is more about how it manages to save in cache with an expiration date, and when the date expires, make the request again Guys I have this code that saves my products in cache, I would like to better understand how it works, getItemById(id) ))
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |