aboutsummaryrefslogtreecommitdiff
path: root/files/pt-pt/web/api/storage_api/index.html
blob: 434cee963dd7d9f58bc0a08dc5049faf9f76bbcc (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
title: API de armazenamento
slug: Web/API/API_armazenamento
tags:
  - API
  - API de armazenamento
  - Armazenamento
  - Contextod e segurança
  - Quotas
  - Referencia
  - Resumo
  - Sinopse
  - Utilização
translation_of: Web/API/Storage_API
---
<p>{{securecontext_header}}{{DefaultAPISidebar("Storage")}}</p>

<p>The Storage Standard defines a common, shared storage system to be used by all APIs and technologies that store content-accessible data for individual Web sites. The Storage API gives sites' code the ability to find out how much space they can use, how much they are already using, and even control whether or not they need to be alerted before the {{Glossary("user agent")}} disposes of site data in order to make room for other things.</p>

<p>{{AvailableInWorkers}}</p>

<p>Site storage—the data stored for a Web site which is managed by the Storage Standard—includes:</p>

<ul>
 <li><a href="/en-US/docs/Web/API/IndexedDB_API">IndexedDB databases</a></li>
 <li><a href="/en-US/docs/Web/API/Cache">Cache API data</a></li>
 <li><a href="/en-US/docs/Web/API/Service_Worker_API">Service Worker registrations</a></li>
 <li><a href="/en-US/docs/Web/API/Web_Storage_API">Web Storage API data</a> managed using {{domxref("window.localStorage")}}</li>
 <li>History state information saved using {{domxref("History.pushState()")}}</li>
 <li><a href="/pt-PT/docs/Web/HTML/Utilizar_a_cache_de_aplicacao">Caches de aplicação</a></li>
 <li><a href="/en-US/docs/Web/API/Notifications_API">Notification data</a></li>
 <li>Other kinds of site-accessible, site-specific data that may be maintained</li>
</ul>

<h2 id="Unidades_de_armazenamento_de_site">Unidades de armazenamento de site</h2>

<p>The site storage system described by the Storage Standard and interacted with using the Storage API consists of a single <strong>site storage unit</strong> for each {{Glossary("origin")}}. In essence, every Web site or Web application has its own storage unit into which its data gets placed. The diagram below shows a site storage pool with three storage units within, showing how storage units can have different data types stored within and may have different quotas (maximum storage limits).</p>

<p><img alt="A diagram showing how the site storage pool consists of multiple storage units that contain data from various APIs as well as possible unused space left before the quota is reached." src="https://mdn.mozillademos.org/files/14379/StorageUnits.png" style="height: 412px; width: 600px;"></p>

<ul>
 <li>Origin 1 has some Web Storage data as well as some IndexedDB data, but also has some free space left; its current usage hasn't yet reached its quota.</li>
 <li>Origin 2 has no data stored in it yet; it's just an empty box waiting for content. This origin, however, has a lower quota than the other two do. It may be a less-visited site, or one known to have lower data storage requirements.</li>
 <li>Origin 3's storage unit is completely full; it's reached its quota and can't store any more data without some existing material being removed.</li>
</ul>

<p>{{Glossary("User agent", "User agents")}} are likely to use various techniques to determine the quota for various origins. One of the most likely methods—one which the specification specifically encourages, in fact—would be to consider the popularity and/or usage levels of individual sites to determine what their quotas should be.  It's also conceivable that the browser might offer a user interface to customize these quotas.</p>

<h2 id="Modos_de_caixa_(Box)">Modos de caixa (Box)</h2>

<p>The actual data storage within each site storage unit is called its <strong>box</strong>. Each site storage unit has exactly one box into which all of its data is placed, and has a <strong>box mode</strong> that describes the data retention policy for that box. There are two modes:</p>

<dl>
 <dt><code>"best-effort"</code></dt>
 <dd>The user agent will try to retain the data contained in the box for as long as it can, <em>but will not warn users</em> if storage space runs low and it becomes necessary to clear the box in order to relieve the storage pressure.</dd>
 <dt><code>"persistent"</code></dt>
 <dd>The user agent will retain the data as long as possible, clearing all <code>"best-effort"</code> boxes before considering clearing a box marked <code>"persistent"</code>. If it becomes necessary to consider clearing persistent boxes, the user agent will notify the user and provide a way to clear one or more persistent boxes as needed.</dd>
</dl>

<p>To change an origin's box mode requires permission to use the <code>"persistent-storage"</code> feature.</p>

<h2 id="Persistência_de_dados_e_limpeza">Persistência de dados e limpeza</h2>

<p>If the site or app has the <strong><code>"persistent-storage"</code></strong> feature permission, it can use the {{domxref("StorageManager.persist()")}} method to request that its box be made persistent. It's also possible for the user agent to decide to make the site's storage unit persistent due to usage characteristics or other metrics. The <code>"persistent-storage"</code> feature's permission-related flags, algorithms, and types are all set to the standard defaults for a permission, except that the <strong>permission state</strong> must be the same across the entire origin, and that if the permission state isn't <code>"granted"</code> (meaning that for whatever reason, access to the persistent storage feature was denied), the origin's site storage unit's box mode is always <code>"best-effort"</code>.</p>

<div class="note">
<p><strong>Nota</strong>: Consulte <a href="/en-US/docs/Web/API/Permissions_API/Using_the_Permissions_API">Using the Permissions API</a> para mais detalhes sobre como obter e gerir as permissões.</p>
</div>

<p>When clearing site storage units, an origin's box is treated as a single entity; if the user agent needs to clear it and the user approves, the entire data store is cleared rather than providing some means of clearing only data from individual APIs.</p>

<p>If a box is marked as <code>"persistent"</code>, the contents won't be cleared by the user agent without either the data's origin itself or the user specifically doing so. This includes scenarios such as the user selecting a "Clear Caches" or "Clear Recent History" option. The user will be asked specifically for permission to remove persistent site storage units.</p>

<h2 id="Quotas_e_estimativas_de_utilização">Quotas e estimativas de utilização</h2>

<p>The user agent determines, using whatever mechanism it chooses, the maximum amount of storage a given site can use. This maximum is the origin's <strong>quota</strong>. The amount of this space which is in use by the site is called its <strong>usage</strong>. Both of these values are estimates; there are several reasons why they're not precise:</p>

<ul>
 <li>User agents are encouraged to obscure the exact size of the data used by a given origin, to prevent these values from being used for fingerprinting purposes.</li>
 <li>De-duplication, compression, and other methods to reduce the physical size of the stored data may be used.</li>
 <li>Quotas are conservative estimates of the space available for the origin's use, and should be less than the available space on the device to help prevent overruns.</li>
</ul>

<p>User agents may use any method they choose to determine the size of origins' quotas, and are encouraged by the specification to provide popular or frequently-used sites with extra space.</p>

<p>To determine the estimated quota and usage values for a given origin, use the {{domxref("StorageManager.estimate", "navigator.storage.estimate()")}} method, which returns a promise that, when resolved, receives a {{domxref("StorageEstimate")}} that contains these figures. For example:</p>

<pre class="brush: js">navigator.storage.estimate().then(estimate =&gt; {
  // estimate.quota is the estimated quota
  // estimate.usage is the estimated number of bytes used
});</pre>

<h2 id="Especificações">Especificações</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Especificação</th>
   <th scope="col">Estado</th>
   <th scope="col">Comentário</th>
  </tr>
  <tr>
   <td>{{SpecName('Storage')}}</td>
   <td>{{Spec2('Storage')}}</td>
   <td>Definição inicial.</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidade_de_navegador">Compatibilidade de navegador</h2>

<div>
<h3 id="StorageManager"><code>StorageManager</code></h3>

<div>


<p>{{Compat("api.StorageManager")}}</p>
</div>
</div>

<h2 id="Consultar_também">Consultar também</h2>

<ul>
 <li>{{domxref("NavigatorStorage.storage", "navigator.storage")}}</li>
 <li>{{domxref("StorageManager")}} (the object returned by <code>navigator.storage</code>)</li>
 <li><a href="/en-US/docs/Web/API/Permissions_API/Using_the_Permissions_API">Using the Permissions API</a></li>
</ul>