@@ -6,8 +6,16 @@ browsers. This namespace helps you to store user data on disk.
66The whole store is read from disk ** before any plugin runs** , and kept in memory
77for the rest of the session. Reads (` get ` , ` has ` ) are therefore synchronous and
88safe to call from your plugin's ` init ` . Writes update memory immediately and
9- commit to disk on a short debounce, so a burst of ` set ` calls (a settings slider,
10- say) collapses into a single write.
9+ reach disk a moment later; repeated ` set ` calls on the same key (a settings
10+ slider, say) collapse into a single write.
11+
12+ ::: tip Storing more than a few settings?
13+
14+ Every plugin shares this one store, and it's all held in memory. For datasets,
15+ caches, or anything that grows, use [ ` context.storage ` ] ( ./storage ) — it's
16+ per-plugin, and the cost of a write doesn't grow with how much you've stored.
17+
18+ :::
1119
1220## DataStore.set()
1321
@@ -34,11 +42,14 @@ functions and runtime objects will be ignored.
3442
3543#### Returns
3644
37- ` true ` if the value was accepted , ` false ` if ` key ` was not a string .
45+ ` true ` if the value was accepted .
3846
39- The return value is ** not ** a write confirmation — it means " stored in memory,
40- and it will reach disk shortly " . Use [`flush()`](#datastore-flush) if you need
41- to know the data is durable .
47+ ` false ` if ` key ` wasn ' t a string, if the value is something JSON can' t represent ,
48+ or if the store is [full ](#storage - limits ).
49+
50+ A ` true ` is ** not ** a write confirmation — it means " stored in memory, and it
51+ will reach disk shortly " . Use [`flush()`](#datastore-flush) if you need to know
52+ the data is durable .
4253
4354#### Example
4455
@@ -172,9 +183,9 @@ function flush(): Promise<void>
172183Writes any pending changes out immediately and resolves once they are durable
173184on disk .
174185
175- Most plugins never need this — the debounced commit already handles normal use .
176- Reach for it when you are about to do something that could end the session
177- before the debounce fires , such as calling ` restartClient() ` .
186+ Most plugins never need this — normal writes reach disk on their own . Reach for
187+ it when you ' re about to do something that could end the session first, such a s
188+ calling ` restartClient() ` .
178189
179190#### Example
180191
@@ -183,3 +194,39 @@ DataStore.set('my-config', config)
183194await DataStore.flush()
184195window.restartClient()
185196` ` `
197+
198+ ## DataStore .usage ()
199+
200+ < Badge type = " info" text = " function" / >
201+ < Badge type = " tip" text = " since v1.2.0" / >
202+
203+ ` ` ` ts
204+ function usage(): Promise<{ used: number, quota: number }>
205+ ` ` `
206+
207+ How much of the store is in use , and the cap — both in bytes .
208+
209+ #### Example
210+
211+ ` ` ` js
212+ const { used, quota } = await DataStore.usage()
213+ console.log( ` $ {Math .round (used / quota * 100 )}% of DataStore used ` )
214+ ` ` `
215+
216+ ## Storage limits
217+
218+ DataStore is capped at ** 128 MB ** , and that budget is ** shared by every
219+ installed plugin ** — it ' s one file. One plugin filling it stops every other
220+ plugin from saving .
221+
222+ When it ' s full, `set` returns `false` and nothing is written; a warning appears
223+ in the console once . Existing data is untouched and still readable . Removing
224+ keys frees space , and writes start working again shortly after .
225+
226+ ::: tip
227+
228+ If you ' re storing anything that grows — cached data, per-match records, a
229+ dataset — use [` context.storage ` ](./ storage ) instead . It ' s per-plugin, gets
230+ 256 MB of its own , and nothing another plugin does can use it up .
231+
232+ :::
0 commit comments