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 Window.caches property in
windows or through the WorkerGlobalScope.caches property in workers.
Note:
CacheStorage
always rejects with aSecurityError
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, becauseCacheStorage
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.
API documentation sourced from MDN Web Docs.
- on
- Implemented types
- Available extensions
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 thecacheName
, and if found, deletes the Cache object and returns aPromise
that resolves totrue
. If no Cache object is found, it resolves tofalse
. -
has(
String cacheName) → JSPromise< JSBoolean> -
The
has()
method of the CacheStorage interface returns aPromise
that resolves totrue
if a Cache object matches thecacheName
. -
keys(
) → JSPromise< JSArray< JSString> > -
The
keys()
method of the CacheStorage interface returns aPromise
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 aPromise
for a Response, or aPromise
which resolves toundefined
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 aPromise
that resolves to the Cache object matching thecacheName
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited