...
/Using the CacheStorage, Geolocation, and OpenWeather One Call APIs
Using the CacheStorage, Geolocation, and OpenWeather One Call APIs
Learn how to call external APIs like CacheStorage, Geolocation, and OpenWeather One Call API.
We'll cover the following...
Using the CacheStorage API
The CacheStorage API is used to cache request/response object pairs where the request
objects are the keys and the response
objects are the values. It was designed to be used by service workers to provide offline functionality. A caches
object is an instance of CacheStorage. It is a global object that is located in the window
object.
We can use the following code to test if it is available on the browser:
const hasCaches = 'caches' in self;
A caches
object is used to maintain a list of caches for a particular web app. Caches cannot be shared with other web apps and they are isolated from the browser’s HTTP cache. They are entirely managed through the JavaScript that we write.
These are some of the methods of CacheStorage:
delete(cacheName)
: This method deletes the indicated cache and returnstrue
. If the indicated cache is not found, it returnsfalse
.has(cacheName)
: This method returnstrue
if the indicated cache exists, andfalse
otherwise.keys
: This method returns a string array of the names of all of the caches.open(cacheName)
: This method opens the indicated cache. If it does not exist, it is created and then opened.
When we open an instance of ...