aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/cachestorage/has/index.html
blob: e724073c44ced5456e3026ac543f8ea0637ad56c (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
83
84
---
title: CacheStorage.has()
slug: Web/API/CacheStorage/has
tags:
  - API
  - CacheStorage
  - Experimental
  - Method
  - Reference
  - Service Workers
  - ServiceWorker
  - has
translation_of: Web/API/CacheStorage/has
---
<p>{{APIRef("Service Workers API")}}</p>

<p><span class="seoSummary">{{domxref("CacheStorage")}} インターフェイスの <strong><code>has()</code></strong> メソッドは、{{domxref("Cache")}} オブジェクトが <code>cacheName</code> と一致する場合に <code>true</code> に解決される {{jsxref("Promise")}} を返します。</span></p>

<p>グローバルな {{domxref("WindowOrWorkerGlobalScope.caches", "caches")}} プロパティを介して <code>CacheStorage</code> にアクセスできます。</p>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox">caches.has(<em>cacheName</em>).then(function(<em>boolean</em>) {
  // true: キャッシュが存在します!
});
</pre>

<h3 id="Parameters" name="Parameters">パラメーター</h3>

<dl>
 <dt><code>cacheName</code></dt>
 <dd> {{domxref("CacheStorage")}} で探している {{domxref("Cache")}} オブジェクトの名前を表す {{domxref("DOMString")}}</dd>
</dl>

<h3 id="Return_value" name="Return_value">戻り値</h3>

<p>キャッシュが存在する場合は <code>true</code>、存在しない場合は <code>false</code> に解決される {{jsxref("Promise")}}</p>

<h2 id="Examples" name="Examples"></h2>

<p>次の例では、最初に <code>'v1'</code> というキャッシュが存在するかどうかを確認します。 その場合、アセットのリストを追加します。 そうでない場合、何らかのキャッシュセットアップ関数を実行します。</p>

<pre class="brush: js">caches.has('v1').then(function(hasCache) {
  if (!hasCache) {
    someCacheSetupfunction();
  } else {
    caches.open('v1').then(function(cache) {
      return cache.addAll(myAssets);
    });
  }
}).catch(function() {
  // ここで例外を処理します。
});</pre>

<h2 id="Specifications" name="Specifications">仕様</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">仕様</th>
   <th scope="col">状態</th>
   <th scope="col">コメント</th>
  </tr>
  <tr>
   <td>{{SpecName('Service Workers', '#cache-storage-has', 'CacheStorage: has')}}</td>
   <td>{{Spec2('Service Workers')}}</td>
   <td>初期定義</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>



<p>{{Compat("api.CacheStorage.has")}}</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li><a href="/ja/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Service worker の使用</a></li>
 <li>{{domxref("Cache")}}</li>
 <li>{{domxref("WindowOrWorkerGlobalScope.caches")}}</li>
</ul>