aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/caches/index.md
blob: abfb9936b249d0a45b00c84f299346c4b4adea0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
title: WindowOrWorkerGlobalScope.caches
slug: Web/API/caches
translation_of: Web/API/WindowOrWorkerGlobalScope/caches
original_slug: Web/API/WindowOrWorkerGlobalScope/caches
---
{{APIRef()}}{{SeeCompatTable}}

La propriété en lecture seule  **`caches`** de l'interface {{domxref("WindowOrWorkerGlobalScope")}} retourne l'objet {{domxref("CacheStorage")}} associé au contexte actuel. Cet objet permet de stocker des ressources pour une utilisation hors-ligne et de générer des réponses personnalisées à des requêtes.

## Syntaxe

    var myCacheStorage = self.caches; // ou simplement caches

### Value

Un objet de type {{domxref("CacheStorage")}}.

## Exemple

L'exemple suivant montre comment mettre en cache un contexte de [service worker](/en-US/docs/Web/API/Service_Worker_API) pour stocker des ressources et les utiliser hors-ligne.

```js
this.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open('v1').then(function(cache) {
      return cache.addAll([
        '/sw-test/',
        '/sw-test/index.html',
        '/sw-test/style.css',
        '/sw-test/app.js',
        '/sw-test/image-list.js',
        '/sw-test/star-wars-logo.jpg',
        '/sw-test/gallery/',
        '/sw-test/gallery/bountyHunters.jpg',
        '/sw-test/gallery/myLittleVader.jpg',
        '/sw-test/gallery/snowTroopers.jpg'
      ]);
    })
  );
});
```

## Spécifications

<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Spécification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>
        {{SpecName('Service Workers', '#self-caches', 'caches')}}
      </td>
      <td>{{Spec2('Service Workers')}}</td>
      <td>
        <p>
          Défini dans un <code>WindowOrWorkerGlobalScope</code> partiel dans la
          nouvelle spec.
        </p>
      </td>
    </tr>
    <tr>
      <td>{{SpecName('Service Workers')}}</td>
      <td>{{Spec2('Service Workers')}}</td>
      <td>Définition initiale.</td>
    </tr>
  </tbody>
</table>

## Compatibilité des navigateurs

{{Compat("api.WindowOrWorkerGlobalScope.caches")}}

## Voir aussi

- [Service Workers](/en-US/docs/Web/API/ServiceWorker_API)
- [Web Workers](/en-US/docs/Web/API/Web_Workers_API)
- {{domxref("CacheStorage")}}
- {{domxref("Cache")}}