A Storage API for JavaScript.
Note: The Web Storage API stores the data on the client. Therefore, you must not use this API for confidential information.
Provides a unified interface and methods to store data on the client using the Web Storage API or a custom implementation. By default, data can be persisted inside localStorage or a sessionStorage.
You can access the 'default' storage by using module:sap/ui/util/Storage methods static on the module export or by creating an own instance of Storage via the constructor.
A typical intended usage of this API is the storage of a string representing the state of a control. In this case, the data is stored in the browser session, and the methods to be used are #put and #get. The method #remove can be used to delete the previously saved state.
For the sake of completeness, the method #clear is available. However, it should be called only in very particular situations, when a global erasing of data is required. If only keys with certain prefix should be deleted, the method #removeAll should be used.
new module:sap/ui/util/Storage(pStorage?, sStorageKeyPrefix?)
Param | Type | Default Value | Description |
---|---|---|---|
pStorage? | module:sap/ui/util/Storage.Type Storage | module:sap/ui/util/Storage.Type.session | The type this storage should be of or an Object implementing the typical Storage API for direct usage. |
sStorageKeyPrefix? | string | 'state.key_' | The prefix to use in this storage. |
Method | Description |
---|---|
clear |
Clears the whole storage (Independent of the current Storage instance!). CAUTION This method should be called only in very particular situations, when a global erasing of data is required. Given that the method deletes the data saved under any ID, it should not be called when managing data for specific controls. |
get |
Retrieves data item for a specific key. |
getType |
Returns the storage type. |
isSupported |
Returns whether the given storage is supported. |
put |
Add key to the storage or updates value if the key already exists. |
remove |
Removes key from storage if it exists. |
removeAll |
Removes all stored keys. |
Clears the whole storage (Independent of the current Storage instance!).
CAUTION This method should be called only in very particular situations, when a global erasing of data is required. Given that the method deletes the data saved under any ID, it should not be called when managing data for specific controls.
Retrieves data item for a specific key.
Param | Type | DefaultValue | Description |
---|---|---|---|
sKey | string |
key to retrieve |
Add key to the storage or updates value if the key already exists.
Param | Type | DefaultValue | Description |
---|---|---|---|
sKey | string |
key to create |
|
sValue | string |
value to create/update |