Cache

open class Cache(source)

The Cache interface provides a persistent storage mechanism for Request / Response object pairs that are cached in long lived memory. How long a Cache object lives is browser dependent, but a single origin's scripts can typically rely on the presence of a previously populated Cache object. Note that the Cache interface is exposed to windowed scopes as well as workers. You don't have to use it in conjunction with service workers, even though it is defined in the service worker spec. Available only in secure contexts.

MDN Reference

Functions

Link copied to clipboard
inline suspend fun Cache.add(url: String)

The add() method of the Cache interface takes a URL, retrieves it, and adds the resulting response object to the given cache.

inline suspend fun Cache.add(request: Request)
inline suspend fun Cache.add(url: URL)
Link copied to clipboard
inline suspend fun Cache.addAll(urls: ReadonlyArray<JsString>)

inline suspend fun Cache.addAll(requests: ReadonlyArray<Request>)

The addAll() method of the Cache interface takes an array of URLs, retrieves them, and adds the resulting response objects to the given cache. The request objects created during retrieval become keys to the stored response operations.

Link copied to clipboard

The addAll() method of the Cache interface takes an array of URLs, retrieves them, and adds the resulting response objects to the given cache. The request objects created during retrieval become keys to the stored response operations.

Link copied to clipboard

The add() method of the Cache interface takes a URL, retrieves it, and adds the resulting response object to the given cache.

fun addAsync(request: Request): Promise<Void?>
fun addAsync(url: URL): Promise<Void?>
Link copied to clipboard
inline suspend fun Cache.delete(url: String): Boolean
inline suspend fun Cache.delete(url: String, options: CacheQueryOptions): Boolean

The delete() method of the Cache interface finds the Cache entry whose key is the request, and if found, deletes the Cache entry and returns a Promise that resolves to true. If no Cache entry is found, it resolves to false.

inline suspend fun Cache.delete(request: Request): Boolean
inline suspend fun Cache.delete(url: URL): Boolean
inline suspend fun Cache.delete(request: Request, options: CacheQueryOptions): Boolean
inline suspend fun Cache.delete(url: URL, options: CacheQueryOptions): Boolean
Link copied to clipboard
fun deleteAsync(url: String, options: CacheQueryOptions = definedExternally): Promise<JsBoolean>

The delete() method of the Cache interface finds the Cache entry whose key is the request, and if found, deletes the Cache entry and returns a Promise that resolves to true. If no Cache entry is found, it resolves to false.

fun deleteAsync(request: Request, options: CacheQueryOptions = definedExternally): Promise<JsBoolean>
fun deleteAsync(url: URL, options: CacheQueryOptions = definedExternally): Promise<JsBoolean>
Link copied to clipboard
inline suspend fun Cache.keys(): ReadonlyArray<Request>
inline suspend fun Cache.keys(url: String): ReadonlyArray<Request>
inline suspend fun Cache.keys(url: String, options: CacheQueryOptions): ReadonlyArray<Request>

The keys() method of the Cache interface returns a Promise that resolves to an array of Request objects representing the keys of the Cache.

inline suspend fun Cache.keys(request: Request): ReadonlyArray<Request>
inline suspend fun Cache.keys(url: URL): ReadonlyArray<Request>
inline suspend fun Cache.keys(request: Request, options: CacheQueryOptions): ReadonlyArray<Request>
inline suspend fun Cache.keys(url: URL, options: CacheQueryOptions): ReadonlyArray<Request>
Link copied to clipboard
fun keysAsync(url: String = definedExternally, options: CacheQueryOptions = definedExternally): Promise<ReadonlyArray<Request>>

The keys() method of the Cache interface returns a Promise that resolves to an array of Request objects representing the keys of the Cache.

fun keysAsync(request: Request, options: CacheQueryOptions = definedExternally): Promise<ReadonlyArray<Request>>
fun keysAsync(url: URL, options: CacheQueryOptions = definedExternally): Promise<ReadonlyArray<Request>>
Link copied to clipboard
inline suspend fun Cache.match(url: String): Response?
inline suspend fun Cache.match(url: String, options: CacheQueryOptions): Response?

The match() method of the Cache interface returns a Promise that resolves to the Response associated with the first matching request in the Cache object. If no match is found, the Promise resolves to undefined.

inline suspend fun Cache.match(request: Request): Response?
inline suspend fun Cache.match(url: URL): Response?
inline suspend fun Cache.match(request: Request, options: CacheQueryOptions): Response?
inline suspend fun Cache.match(url: URL, options: CacheQueryOptions): Response?
Link copied to clipboard
inline suspend fun Cache.matchAll(): ReadonlyArray<Response>
inline suspend fun Cache.matchAll(url: String): ReadonlyArray<Response>
inline suspend fun Cache.matchAll(url: String, options: CacheQueryOptions): ReadonlyArray<Response>

The matchAll() method of the Cache interface returns a Promise that resolves to an array of all matching responses in the Cache object.

inline suspend fun Cache.matchAll(request: Request): ReadonlyArray<Response>
inline suspend fun Cache.matchAll(url: URL): ReadonlyArray<Response>
inline suspend fun Cache.matchAll(request: Request, options: CacheQueryOptions): ReadonlyArray<Response>
inline suspend fun Cache.matchAll(url: URL, options: CacheQueryOptions): ReadonlyArray<Response>
Link copied to clipboard
fun matchAllAsync(url: String = definedExternally, options: CacheQueryOptions = definedExternally): Promise<ReadonlyArray<Response>>

The matchAll() method of the Cache interface returns a Promise that resolves to an array of all matching responses in the Cache object.

fun matchAllAsync(request: Request, options: CacheQueryOptions = definedExternally): Promise<ReadonlyArray<Response>>
fun matchAllAsync(url: URL, options: CacheQueryOptions = definedExternally): Promise<ReadonlyArray<Response>>
Link copied to clipboard
fun matchAsync(url: String, options: CacheQueryOptions = definedExternally): Promise<Response?>

The match() method of the Cache interface returns a Promise that resolves to the Response associated with the first matching request in the Cache object. If no match is found, the Promise resolves to undefined.

fun matchAsync(request: Request, options: CacheQueryOptions = definedExternally): Promise<Response?>
fun matchAsync(url: URL, options: CacheQueryOptions = definedExternally): Promise<Response?>
Link copied to clipboard
inline suspend fun Cache.put(url: String, response: Response)

The put() method of the Cache interface allows key/value pairs to be added to the current Cache object.

inline suspend fun Cache.put(request: Request, response: Response)
inline suspend fun Cache.put(url: URL, response: Response)
Link copied to clipboard
fun putAsync(url: String, response: Response): Promise<Void?>

The put() method of the Cache interface allows key/value pairs to be added to the current Cache object.

fun putAsync(request: Request, response: Response): Promise<Void?>
fun putAsync(url: URL, response: Response): Promise<Void?>