Chapter 12. Persistent Storage

Provides services to store and retrieve profile and app specific data. There are three types of storage available to profiles and apps:

  • Store currentAppConfig — An object that stores app data only.
  • Store currentAppData — An object that stores data associated with both the app and the profile.
  • Store currentProfileData — An object that stores profile data only. This data is private for a profile, but available to all apps and can be overwritten by another app if the same access key is used.

Associated with the current profile

Not associated with any profiles

Associated with the current app

Store currentAppData

currentAppData.type == 'APP'

This storage is associated with both a profile and an app. Data stored here is different from profile to profile, and from app to app.

Store currentAppConfig

currentAppConfig.type == 'APP_CONFIG'

This storage is associated with an app. Data stored here does not change if the profile is switched, but is different from app to app.

Not associated with any app

Store currentProfileData

currentProfileData.type == 'PROFILE'

This storage is associated with a profile. Data stored here does not change if the app is changed, but is different from profile to profile. This data is available to all apps and can be overwritten by another app if the same access key is used.

Not Supported.

Apps and profiles can store primitive JavaScript String values. To store JSONable JavaScript objects use JSON.stringify() to store and JSON.parse() to retrieve the values. The information stored persists after exiting the app, launching a new app, or switching profiles. The storage is independent of the app's lifecycle. Only uninstalling the app removes all app data. Deleting the profile removes all profile data.

Each data element in the Store object is a name-value pair. A name-value pair or key-value pair is a fundamental data representation in computing systems and applications. Each Store object instantiation is a set of key-value pairs providing an open-ended data structure that allows for future extension without modifying existing code or data. The data model can be expressed as a collection of string tuples “name, value”. Keys are unique only within each Store object.

You access the three types of storage objects in the following ways:

  • Get Methods
    • currentAppConfig.get()
    • currentAppData.get()
    • currentProfileData.get()
  • Set Methods
    • currentAppConfig.set()
    • currentAppData.set()
    • currentProfileData.set()

Storage Class

Provides data storage services through the Store class for apps, profiles, and app/profile combinations. Use the global namespaces defined by currentProfileData, currentAppData, and currentAppConfig.

Current Application Configuration

use the currentAppConfig namespace to access app data that does not change with the profile

This storage is associated with an app. Data stored here does not change if the profile is switched, but is different from app to app. The same key may be found in currentProfileData, currentAppData, and currentAppConfig.

Example

Properties

Property

Type

Description

appID

String

The unique string identifier of the app associated with this data storage.

profileID

String

Returns null because the data storage is not associated with a profile and its type is 'APP_CONFIG'.

type

String

The type of the data store represented as a String. Returns: 'APP_CONFIG'. The data store belongs to an application.

Methods

Boolean delete(String key)

Deletes the key-value pair specified by the given unique key . The parameter key is a unique String to identify the storage to be deleted. Returns true if successful or if the key is not found.

String get(String key)

Returns the data storage value associated with the given unique key . The parameter key is a unique String to retrieve the data store value. Returns null if the key does not exist in this data store.

Array getIDs()

Returns an array of strings containing all existing keys for this data store. If no keys exist, this method returns an empty array.

Boolean set(String key, String value)

Sets a value associated with a unique key . The parameter key is a unique string to identify the storage associated with the given string value . The parameter value is the string which is stored and associated with the given string key . If the value is a JSONable JavaScript object, first call JSON.stringify() so that the JSON string is stored. Returns true if successful.

Current Application Data

use the currentAppData namespace to access app and profile data

This storage is associated with both a profile and an app. Data stored here is different from profile to profile, and from app to app. The same key may be found in currentProfileData, currentAppData, and currentAppConfig.

Example

Properties

Property

Type

Description

appID

String

The unique string identifier of the app associated with this data storage.

profileID

String

The unique string identifier of the profile associated with this data storage.

type

String

The type of the data store represented as a String. Returns: 'APP'. The data store is associated to both an application and a profile.

Methods

Boolean delete(String key)

Deletes the key-value pair specified by the given unique key . The parameter key is a unique String to identify the storage to be deleted. Returns true if successful or if the key is not found.

String get(String key)

Returns the data storage value associated with the given unique key . The parameter key is a unique String to retrieve the data store value. Returns null if the key does not exist in this data store.

Array getIDs()

Returns an array of strings containing all existing keys for this data store. If no keys exist, this method returns an empty array.

Boolean set(String key, String value)

Sets a value associated with a unique key . The parameter key is a unique string to identify the storage associated with the given string value . The parameter value is the string which is stored and associated with the given string key . If the value is a JSONable JavaScript object, first call JSON.stringify() so that the JSON string is stored. Returns true if successful.

Current Profile Data

use the currentProfileData namespace to access profile data that does not change with the app

This storage is associated with a profile. Data stored here does not change if the app is changed, but is different from profile to profile. This data is available to all apps and can be overwritten by another app if the same access key is used. The same key may be found in currentProfileData, currentAppData, and currentAppConfig.

Example

Properties

Property

Type

Description

appID

String

Returns null because the data store is not associated with an app and its type is 'PROFILE'.

profileID

String

The unique string identifier of the profile associated with this data storage.

type

String

The type of the data store represented as a String. Returns: 'PROFILE'. The data store belongs to a profile.

Methods

Boolean delete(String key)

Deletes the key-value pair specified by the given unique key . The parameter key is a unique String to identify the storage to be deleted. Returns true if successful or if the key is not found.

String get(String key)

Returns the data storage value associated with the given unique key . The parameter key is a unique String to retrieve the data store value. Returns null if the key does not exist in this data store.

Array getIDs()

Returns an array of strings containing all existing keys for this data store. If no keys exist, this method returns an empty array.

Boolean set(String key, String value)

Sets a value associated with a unique key . The parameter key is a unique string to identify the storage associated with the given string value . The parameter value is the string which is stored and associated with the given string key . If the value is a JSONable JavaScript object, first call JSON.stringify() so that the JSON string is stored. Returns true if successful.

Table of Contents