WebStoragePersistence Class

The persistent storage of the local storage areas of a StorageShed (window.localStorage), e.g. a file or a database. The shed keeps the items of a storage area in memory: it loads them with WebStoragePersistence.LoadItems the first time the area of an origin is used, and calls the other methods after each change, so that an implementation only stores the items.

public abstract class WebStoragePersistence

Remarks

The methods are called synchronously by the scripts (localStorage.setItem()...): an implementation that writes to a slow storage should buffer the changes and write them in the background (and expose a way to flush them). The changes of a storage area are reported in order, but the areas of different origins can be changed concurrently by the browsing contexts of several threads, so the implementation must be thread-safe.

The quota of the shed is enforced on the items in memory. A storage area whose loaded items exceed it keeps them, but cannot grow. The areas of the documents of the credentialless iframes are partitioned by their page and are not persisted: they are kept in memory only.

Constructors

NameDescription
WebStoragePersistence()

WebStoragePersistence()

protected WebStoragePersistence()

No documentation is available.

Methods

NameDescription
ClearAll()Removes the items of all the origins (StorageShed.Clear).
ClearItems(string)Removes all the items of the storage area of an origin. An exception is thrown by clear(), and the items are not removed.
LoadItems(string)Returns the persisted items of the storage area of an origin. The order of the items is the order of localStorage.key() (the shed appends the new keys, and keeps the position of a key whose value changes). An exception makes localStorage throw a SecurityError (the storage bottle map cannot be obtained), and the area is loaded again the next time it is used.
RemoveItem(string, string)Removes a key of the storage area of an origin. An exception is thrown by removeItem(), and the item is not removed.
SetItem(string, string, string)Stores the value of a key of the storage area of an origin (a new key, or a new value). An exception makes setItem() throw a QuotaExceededError, and the item is not changed.

ClearAll()

Removes the items of all the origins (StorageShed.Clear).

public abstract void ClearAll()

ClearItems(string)

Removes all the items of the storage area of an origin. An exception is thrown by clear(), and the items are not removed.

public abstract void ClearItems(string origin)

Parameters

origin string
The serialization of the origin.

LoadItems(string)

Returns the persisted items of the storage area of an origin. The order of the items is the order of localStorage.key() (the shed appends the new keys, and keeps the position of a key whose value changes). An exception makes localStorage throw a SecurityError (the storage bottle map cannot be obtained), and the area is loaded again the next time it is used.

public abstract IEnumerable<KeyValuePair<string, string>> LoadItems(string origin)

Parameters

origin string
The serialization of the origin (e.g. https://example.com, or http://example.com:8080).

Returns

IEnumerable<KeyValuePair<string, string>>

RemoveItem(string, string)

Removes a key of the storage area of an origin. An exception is thrown by removeItem(), and the item is not removed.

public abstract void RemoveItem(string origin, string key)

Parameters

origin string
The serialization of the origin.
key string
The key.

SetItem(string, string, string)

Stores the value of a key of the storage area of an origin (a new key, or a new value). An exception makes setItem() throw a QuotaExceededError, and the item is not changed.

public abstract void SetItem(string origin, string key, string value)

Parameters

origin string
The serialization of the origin.
key string
The key.
value string
The new value.