aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/cache/add
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/fr/web/api/cache/add
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/fr/web/api/cache/add')
-rw-r--r--files/fr/web/api/cache/add/index.html116
1 files changed, 116 insertions, 0 deletions
diff --git a/files/fr/web/api/cache/add/index.html b/files/fr/web/api/cache/add/index.html
new file mode 100644
index 0000000000..25846672e0
--- /dev/null
+++ b/files/fr/web/api/cache/add/index.html
@@ -0,0 +1,116 @@
+---
+title: Cache.add()
+slug: Web/API/Cache/add
+tags:
+ - API
+ - Add
+ - Cache
+ - Experimental
+ - Méthode
+ - Reference
+ - Service Worker
+ - Service worker API
+ - ServiceWorker
+translation_of: Web/API/Cache/add
+---
+<p>{{APIRef("Service Workers API")}}{{SeeCompatTable}}</p>
+
+<p>La méthode <strong><code>add()</code></strong> de l'interface {{domxref("Cache")}} accepte une URL, la récupère, et ajoute l'objet réponse qui en résulte dans le cache. La méthode <code>add()</code> est équivalent au code suivant :</p>
+
+<pre class="brush: js">fetch(url).then(function(response) {
+ if (!response.ok) {
+ throw new TypeError('bad response status');
+ }
+ return cache.put(url, response);
+})</pre>
+
+<p>Pour des opérations plus complexes, il faut utiliser {{domxref("Cache.put","Cache.put()")}} directement.</p>
+
+<div class="note">
+<p><strong>Note</strong>: <code>add()</code> écrasera toute paire clé/valeur précedemment stockée en cache et qui correspond à la requête.</p>
+</div>
+
+<h2 id="Syntaxe">Syntaxe</h2>
+
+<pre class="sytaxbox"><em>cache</em>.add(<em>request</em>).then(function() {
+ //request a été ajoutée au cache
+});
+</pre>
+
+<h3 id="Paramètres">Paramètres</h3>
+
+<dl>
+ <dt>request</dt>
+ <dd>La requête à mettre en cache. Ce paramètre peut être un objet {{domxref("Request", "Requête")}} ou une URL.</dd>
+</dl>
+
+<h3 id="Retour">Retour</h3>
+
+<p>Une {{jsxref("Promise", "Promesse")}} qui est résolue en void.</p>
+
+<h3 id="Exceptions">Exceptions</h3>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col"><strong>Exception</strong></th>
+ <th scope="col"><strong>Arrive quand</strong></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>TypeError</code></td>
+ <td>
+ <p>Le schéma d'URL n'est pas <code>http</code> ou <code>https</code>.</p>
+
+ <p>Le statut de la réponse n'est pas dans les 200 (i.e., une requête qui a échoué.) Cela peut arriver si la requête échoue, mais également si la requête est une <em>cross-origin no-cors</em> (auquel cas le statut retourné est systématiquement 0.)</p>
+ </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Exemples">Exemples</h2>
+
+<p>Ce bloc de code attends le déclenchement d'un {{domxref("InstallEvent")}}, puis lance {{domxref("ExtendableEvent.waitUntil","waitUntil")}} qui gère la phase d'installation de l'application. Cela consite à appeler {{domxref("CacheStorage.open")}} afin de créer un nouveau cache, puis à utiliser {{domxref("Cache.add")}} pour y ajouter des ressources.</p>
+
+<pre class="brush: js">this.addEventListener('install', function(event) {
+ event.waitUntil(
+ caches.open('v1').then(function(cache) {
+ return cache.add('/sw-test/index.html');
+ })
+ );
+});
+</pre>
+
+<h2 id="Spécifications">Spécifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spécification</th>
+ <th scope="col">Statut</th>
+ <th scope="col">Commentaire</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Service Workers', '#dom-cache-add', 'Cache: add')}}</td>
+ <td>{{Spec2('Service Workers')}}</td>
+ <td>Définition initiale.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
+
+<div>
+<div class="hidden">Le tableau de compatibilité sur cette page est généré à partir de données structurées. Si vous souhaitez contribuer aux données, veuillez consulter <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> et nous envoyer une <em>pull request</em>.</div>
+
+<p>{{Compat("api.Cache.add")}}</p>
+</div>
+
+<h2 id="Voir_aussi">Voir aussi</h2>
+
+<ul>
+ <li><a href="/fr/docs/Web/API/Service_Worker_API/Using_Service_Workers">Utiliser les Service Workers</a></li>
+ <li>{{domxref("Cache")}}</li>
+ <li>{{domxref("WorkerGlobalScope.caches")}}</li>
+</ul>