Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

CacheStorage.has()

This article needs a technical review. How you can help.

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The has() method of the CacheStorage interface returns a Promise that resolves to true if a Cache object matches the cacheName.

Syntax

caches.has(cacheName).then(function(true) {
  // your cache exists!
});

Returns

a Promise that resolves to true if the cache exists or false if not.

Parameters

cacheName
A DOMString representing the name of the Cache object you are looking for in the CacheStorage.

Examples

The following example first checks whether a cache called 'v1' exists. If so, we add a list of assets to it. If not (meaning the has() promise would reject) then we run some kind of cache set-up function.

caches.has('v1').then(function(hasCache) {
  if (!hasCache) {
    someCacheSetupfunction();
  } else {
    caches.open('v1').then(function(cache) {
      return cache.addAll(myAssets);
    });
  }
}).catch(function() {
  // Handle exception here.
});;

Specifications

Specification Status Comment
Service Workers
The definition of 'CacheStorage' in that specification.
Working Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 40.0 44 (44)[1] No support ? No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support No support 44.0 (44) (Yes) (Yes) (Yes) 40.0

[1] Service workers (and Push) have been disabled in the Firefox 45 Extended Support Release (ESR.)

See also

Document Tags and Contributors

 Contributors to this page: tarjei, chrisdavidmills, jpmedley, kscarfone
 Last updated by: tarjei,