Storage
In this example we will show you how you can use the Storage API to save and/or share data across different Custom User Interfaces. One very common usage of this is, for example, to share data between Template UIs and Show UIs.
Client Side Storage
There are 3 types of storage methods that reside on the client (not the server), and are therefore only available locally to the specific client.
Tip
If you need to share data across different clients please use the Global Variables
- globalStorage - Data stored in the globalStorage is availble to all user interfaces on the specific client.
- localStorage - Data stored in the localStorage is only accessible to the specific user interface.
- sessionStorage - Data stored in the sessionStorage is availble to all user interfaces on the specific client, similar to globalStorage, however it is not persistent, meaning that it will be deleted when the session ends (page refresh, server restart, client restart etc.)
Example commands:
1 2 3 4 5 6 7 8 9 10 |
|
You can also store JSON data in each of the storage methods, however you will need to stringify and parse the data as follows:
1 2 3 4 5 6 7 8 9 10 11 |
|
Global Variables
Global Variables are saved on the server side and is consistent, meaning that it can be accessed by all clients connected to the server. The data stored can be any valid JS value (string / boolean / nuber / object / ...)
Tip
Global variable API is promise based as it requires communication with the server
Example command:
1 2 3 4 5 6 7 8 9 |
|
Info
The Storage API is derived from the official MDN Storage API
Get All Stored Keys
We can retrieve all the stored keys in any of the storage methods with the following code example:
1 2 3 4 |
|
Example Files
This Example UI shows how you can store and retrieve data using all 4 storage methods.