CacheStorage extension type

The CacheStorage interface represents the storage for Cache objects.

The interface:

  • Provides a master directory of all the named caches that can be accessed by a ServiceWorker or other type of worker or window scope (you're not limited to only using it with service workers).
  • Maintains a mapping of string names to corresponding Cache objects.

Use CacheStorage.open to obtain a Cache instance.

Use CacheStorage.match to check if a given Request is a key in any of the Cache objects that the CacheStorage object tracks.

You can access CacheStorage through the global caches property.

Note: CacheStorage always rejects with a SecurityError on untrusted origins (i.e. those that aren't using HTTPS, although this definition will likely become more complex in the future.) When testing on Firefox, you can get around this by checking the Enable Service Workers over HTTP (when toolbox is open) option in the Firefox Devtools options/gear menu. Furthermore, because CacheStorage requires file-system access, it may be unavailable in private mode in Firefox.

Note: CacheStorage.match is a convenience method. Equivalent functionality to match a cache entry can be implemented by returning an array of cache names from CacheStorage.keys, opening each cache with CacheStorage.open, and matching the one you want with Cache.match.

on
Implemented types

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

delete(String cacheName) JSPromise<JSBoolean>
The delete() method of the CacheStorage interface finds the Cache object matching the cacheName, and if found, deletes the Cache object and returns a Promise that resolves to true. If no Cache object is found, it resolves to false.
has(String cacheName) JSPromise<JSBoolean>
The has() method of the CacheStorage interface returns a Promise that resolves to true if a Cache object matches the cacheName.
keys() JSPromise<JSArray<JSString>>
The keys() method of the CacheStorage interface returns a Promise that will resolve with an array containing strings corresponding to all of the named Cache objects tracked by the CacheStorage object in the order they were created. Use this method to iterate over a list of all Cache objects.
match(RequestInfo request, [MultiCacheQueryOptions options]) JSPromise<Response?>
The match() method of the CacheStorage interface checks if a given Request or URL string is a key for a stored Response. This method returns a Promise for a Response, or a Promise which resolves to undefined if no match is found.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(String cacheName) JSPromise<Cache>
The open() method of the CacheStorage interface returns a Promise that resolves to the Cache object matching the cacheName.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited