JavaScript Programmer’s Reference by Jonathan Reid & Thomas Valentine
Author:Jonathan Reid & Thomas Valentine
Language: eng
Format: epub
ISBN: 9781430246299
Publisher: Apress
Data Caching
As you do more asynchronous programming with XMLHttpRequest, it’s not uncommon to find yourself wanting to cache data locally for speed and efficiency. This is particularly true with mobile applications, where having a local cache of data can not only speed up your application (because accessing cached data is faster than going over the potentially quite slow network) but also make your application use less battery power (because accessing the network requires power). Even for desktop applications it’s common to want to cache commonly used information that doesn’t change very often.
Data caches are very simple, and typically consist of an identifier representing the service or data source, a timestamp of the last time the service was accessed, and the data that was returned the last time the service was accessed. Every time you look at the cache, you can see if the data you want is cached; if it isn’t, you can simply call the service and cache it with a new timestamp. If there is data in the cache, you check its timestamp. If it was accessed too long ago, you’ll know you need to access the service and cache the new results. But if it wasn’t accessed too long ago, you can just use the cached data.
We’ve already built a doXHR() function in the Asynchronous Communication using XMLHttpRequest section above. When we call that method, we provide an object that specifies the URL to call, as well as other information (such as a success method to call, or an error method to call). What would be nice is if we specified a length of time as a property, the doXHR() function would know that we want to cache the data from that URL and it could perform as follows:
Check to see if there is already data in our hypothetical cache.
If the data does not exist in the cache, go and fetch the data from the URL, and save it in the cache with the current timestamp.
If the data does exist in the cache, check the timestamp.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8300)
Test-Driven Development with Java by Alan Mellor(6724)
Data Augmentation with Python by Duc Haba(6639)
Principles of Data Fabric by Sonia Mezzetta(6390)
Learn Blender Simulations the Right Way by Stephen Pearson(6290)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6161)
Hadoop in Practice by Alex Holmes(5958)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5807)
RPA Solution Architect's Handbook by Sachin Sahgal(5559)
Big Data Analysis with Python by Ivan Marin(5365)
The Infinite Retina by Robert Scoble Irena Cronin(5249)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5147)
Pretrain Vision and Large Language Models in Python by Emily Webber(4328)
Infrastructure as Code for Beginners by Russ McKendrick(4089)
Functional Programming in JavaScript by Mantyla Dan(4038)
The Age of Surveillance Capitalism by Shoshana Zuboff(3950)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3804)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3607)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3579)
