StorageShed Class
The local storage areas of Web Storage (window.localStorage): a storage shed (https://storage.spec.whatwg.org/#storage-shed) whose shelves are keyed by origin, each with the localStorage bottle of its origin. The items are kept in memory, and are persisted by the WebStoragePersistence given to the constructor, if any.
public sealed class StorageShedRemarks
A shed can be shared by several browsing contexts (see BrowsingContextOptions.LocalStorage): the documents of the same origin read and write the same items, and the storage events are fired at the windows of the browsing contexts that share the shed. The shed is thread-safe.
The items of a storage area are limited by StorageShed.Quota: the sum of the lengths of the keys and the values, in UTF-16 code units. setItem() throws a QuotaExceededError when the new item would exceed it.
Constructors
| Name | Description |
|---|---|
| StorageShed() | Creates an empty shed whose storage areas have the default quota (StorageShed.DefaultQuota). |
| StorageShed(WebStoragePersistence) | Creates a shed whose storage areas are persisted, with the default quota (StorageShed.DefaultQuota). |
| StorageShed(WebStoragePersistence?, long) | Creates a shed whose storage areas are persisted. |
| StorageShed(long) | Creates an empty shed. |
StorageShed overloads
StorageShed()
StorageShed.csCreates an empty shed whose storage areas have the default quota (StorageShed.DefaultQuota).
public StorageShed()StorageShed(WebStoragePersistence)
StorageShed.csCreates a shed whose storage areas are persisted, with the default quota (StorageShed.DefaultQuota).
public StorageShed(WebStoragePersistence persistence)Parameters
persistenceWebStoragePersistence- The persistent storage of the storage areas.
StorageShed(WebStoragePersistence?, long)
StorageShed.csCreates a shed whose storage areas are persisted.
public StorageShed(WebStoragePersistence? persistence, long quota)Parameters
persistenceWebStoragePersistence?- The persistent storage of the storage areas, or null to keep them in memory only.
quotalong- The maximum size of a storage area: the sum of the lengths of its keys and values, in UTF-16 code units.
StorageShed(long)
StorageShed.csProperties
| Name | Description |
|---|---|
| Persistence | Gets the persistent storage of the storage areas, or null when they are kept in memory only. |
| Quota | Gets the maximum size of a storage area: the sum of the lengths of its keys and values, in UTF-16 code units. |
Persistence
StorageShed.csGets the persistent storage of the storage areas, or null when they are kept in memory only.
public WebStoragePersistence? Persistence { get; }Property value
Quota
StorageShed.csMethods
| Name | Description |
|---|---|
| Clear() | Removes the items of all the origins, and the persisted items of StorageShed.Persistence. No storage event is fired. |
| GetItems(string) | Returns the items of the storage area of an origin, in the order of Storage.key(). The items of an origin that was not used yet are loaded from StorageShed.Persistence. |
| GetOrigins() | Returns the origins whose storage area has items in memory (the areas loaded from StorageShed.Persistence and the ones the documents used), e.g. to save the storage state of a session. |
| SetItem(string, string, string) | Sets an item of the storage area of an origin (e.g. to restore the storage state of a session, as the storageState option of Playwright). No storage event is fired. |
Clear()
StorageShed.csRemoves the items of all the origins, and the persisted items of StorageShed.Persistence. No storage event is fired.
public void Clear()GetItems(string)
StorageShed.csReturns the items of the storage area of an origin, in the order of Storage.key(). The items of an origin that was not used yet are loaded from StorageShed.Persistence.
public IReadOnlyList<KeyValuePair<string, string>> GetItems(string origin)Parameters
originstring- The serialization of the origin (e.g.
https://example.com, orhttp://example.com:8080).
Returns
GetOrigins()
StorageShed.csReturns the origins whose storage area has items in memory (the areas loaded from StorageShed.Persistence and the ones the documents used), e.g. to save the storage state of a session.
public IReadOnlyList<string> GetOrigins()Returns
SetItem(string, string, string)
StorageShed.csSets an item of the storage area of an origin (e.g. to restore the storage state of a session, as the storageState option of Playwright). No storage event is fired.
Parameters
originstring- The serialization of the origin (e.g.
https://example.com, orhttp://example.com:8080). keystring- The key of the item.
valuestring- The value of the item.
Returns
bool True when the item is set, false when it exceeds the quota of the storage area (see StorageShed.Quota).
Constants
| Name | Description |
|---|---|
| DefaultQuota | The default quota of a storage area: 5 Mi UTF-16 code units (https://storage.spec.whatwg.org/#registered-storage-endpoints: 5 MiB). |
DefaultQuota
The default quota of a storage area: 5 Mi UTF-16 code units (https://storage.spec.whatwg.org/#registered-storage-endpoints: 5 MiB).
public const long DefaultQuota = 5242880L