Skip to main content

Storage

To persist data on a device the storage utils can be used to work with either localStorage, sessionStorage, or cookie to write, read and delete values. Use cookies as a stage location when values should also be transmitted with each request. The localStorage can be used to persist data for a longer period and across all the browser's tabs. As a volatile memory for one specific task, the sessionStorage can be a good choice in terms of short-term persistence, where data is only available in one tab.

Following a privacy-by-design approach, the storage utils have an in-build max-age functionality, to specify the maximum lifetime of a value. The default is set to 30 minutes. While cookies get deleted automatically by a browser, this doesn't apply to localStorage and sessionStorage.

Values are written as JSON strings in the format of { e: 1525779420000, v: "value"} where e is the expiration date and v is the value. The storageRead function checks if the expiration date is still valid and will eventually delete an expired entry and return '' in both cases.

warning

Accessing and working with all storage types might require consent.

storageWrite

Used to write a value to a key in a storage that can be either local, session (default) or cookie. With maxAgeInMinutes an expiration date can be set. The domain is only required when using cookie as a storage type.

// storageWrite(key, value, maxAgeInMinutes=30, storage='session', domain): WalkerOS.PropertyType

// Write elbUserId us3r1d to the localStorage, valid for 60 min and automatically
// returns the value 'us3r1d' using storageRead.
storageWrite('elbSESSIONId', 'us3r1d', 60, 'local');

storageRead

Accessing the elbUserId from a storage with an in-build max-age check that eventually deletes an expired entry and returns either the value or ''.

// storageRead(key, storage='session'): Walker.PropertyType

// Read the elbUserId from localStorage
storageRead('elbUserId', 'local');

storageDelete

Used to delete a key from a storage.

// storageDelete(key, storage='session'): void

// Delete the elbUserId from localStorage
storageDelete('elbUserId', 'local');