diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:45 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:45 -0500 |
commit | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (patch) | |
tree | 0dd8b084480983cf9f9680e8aedb92782a921b13 /files/es/web/api/cachestorage/keys | |
parent | 4b1a9203c547c019fc5398082ae19a3f3d4c3efe (diff) | |
download | translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.tar.gz translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.tar.bz2 translated-content-1109132f09d75da9a28b649c7677bb6ce07c40c0.zip |
initial commit
Diffstat (limited to 'files/es/web/api/cachestorage/keys')
-rw-r--r-- | files/es/web/api/cachestorage/keys/index.html | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/files/es/web/api/cachestorage/keys/index.html b/files/es/web/api/cachestorage/keys/index.html new file mode 100644 index 0000000000..eee8e0e443 --- /dev/null +++ b/files/es/web/api/cachestorage/keys/index.html @@ -0,0 +1,74 @@ +--- +title: CacheStorage.keys() +slug: Web/API/CacheStorage/keys +translation_of: Web/API/CacheStorage/keys +--- +<p><font><font>{{APIRef ("API de Service Workers")}}</font></font></p> + +<p><span class="seoSummary"><font><font>El </font></font><code><strong>keys</strong></code><strong><code>()</code></strong><font><font>método de la interfaz {{domxref ("CacheStorage")}} devuelve un {{jsxref ("Promise")}} que se resolverá con una matriz que contiene las cadenas correspondientes a todos los {{domxref ("Cache")}} objetos rastreados por el objeto {{domxref ("CacheStorage")}} en el orden en que fueron creados. </font><font>Use este método para iterar sobre una lista de todos los objetos {{domxref ("Cache")}}.</font></font></span></p> + +<p><font><font>Puede acceder a </font></font><code>CacheStorage</code><font><font>través de la propiedad global {{domxref ("WindowOrWorkerGlobalScope.caches", "caches")}}.</font></font></p> + +<h2 id="Sintaxis"><font><font>Sintaxis</font></font></h2> + +<pre class="syntaxbox notranslate"><font><font>caches.keys().then(function(</font></font><em><font><font>keyList</font></font></em><font><font>) {</font></font><font><font> + // haz algo con tu keyList</font></font><font><font> +});</font></font> +</pre> + +<h3 id="Parámetros"><font><font>Parámetros</font></font></h3> + +<p><font><font>Ninguna.</font></font></p> + +<h3 id="Valor_de_retorno"><font><font>Valor de retorno</font></font></h3> + +<p>a {{jsxref("Promise")}} that resolves with an array of the {{domxref("Cache")}} names inside the {{domxref("CacheStorage")}} object.</p> + +<h2 id="Examples" style="line-height: 30px; font-size: 2.14285714285714rem;">Examples</h2> + +<p>In this code snippet we wait for an {{domxref("ServiceWorkerGlobalScope.onactivate", "activate")}} event, and then run a {{domxref("ExtendableEvent.waitUntil","waitUntil()")}} block that clears up any old, unused caches before a new service worker is activated. Here we have a whitelist containing the names of the caches we want to keep (<code>cacheWhitelist</code>). We return the keys of the caches in the {{domxref("CacheStorage")}} object using <code>keys()</code>, then check each key to see if it is in the whitelist. If not, we delete it using {{domxref("CacheStorage.delete()")}}.</p> + +<pre class="brush: js notranslate"><font><font><font><font>then.addEventListener('activar', función (evento) { </font></font></font></font><font><font><font><font> + var cacheWhitelist = ['v2']; </font></font></font></font> +<font><font><font><font> + event.waitUntil( </font></font></font></font><font><font><font><font> + caches.keys().then(function(keyList) { </font></font></font></font><font><font><font><font> + return Promise.all(keyList.map(function(key) {</font></font></font></font><font><font> + if (cacheWhitelist.indexOf(key) === -1) { + return caches.delete(<font><font>key</font></font>); + } + }); + })</font></font><font><font> + );</font></font><font><font> +});</font></font></pre> + +<h2 id="Especificaciones"><font><font>Especificaciones</font></font></h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col"><font><font>Especificación</font></font></th> + <th scope="col"><font><font>Estado</font></font></th> + <th scope="col"><font><font>Comentario</font></font></th> + </tr> + <tr> + <td><font><font>{{SpecName('Service Workers', '# dom-cachestorage-keys', 'CacheStorage: keys')}}</font></font></td> + <td><font><font>{{Spec2 ('Trabajadores de servicio')}}</font></font></td> + <td><font><font>Definición inicial</font></font></td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_del_navegador"><font><font>Compatibilidad del navegador</font></font></h2> + + + +<p><font><font>{{Compat("api.CacheStorage.keys")}}</font></font></p> + +<h2 id="Ver_también"><font><font>Ver también</font></font></h2> + +<ul> + <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers"><font><font>Uso de trabajadores del servicio</font></font></a></li> + <li><font><font>{{domxref("Cache")}}</font></font></li> + <li><font><font><font><font>{{domxref("WindowOrWorkerGlobalScope.caches")}}</font></font></font></font></li> +</ul> |