The apex.storage namespace contains all functions related browser storage features such as cookies and session storage.
Local storage and session storage, collectively known as web storage, are a browser feature that securely stores key value pairs associated with an origin (web site). The keys and values are strings. The amount of storage space for web storage is greater than that of cookies but it is not unlimited. Another advantage over cookies is that the key value pars are not transmitted with each request.
Both local storage and session storage use the same API to set, get, and remove name value pairs. The difference is that session storage goes away when the browser session ends and local storage is available even when the browser restarts. Keep in mind that the browser is free to limit or delete data stored in local storage at the user's request. Unlike data stored on the server local storage is not shared between browsers on different machines or even different browsers on the same machine.
Because APEX supports multiple applications, multiple workspaces and even instances of the same application running in multiple workspaces there can arise conflicts with using web storage because all the apps from a single APEX instance (which is a single origin or web site) share the same web storage space. The apex.storage.getScopedLocalStorage and apex.storage.getScopedSessionStorage solve this problem buy partitioning the storage into a scope based on application id an optionally additional information such as page id and region id. The scope is crated by using a prefix on all the storage keys. This avoids conflicts when different apps or different instances of the same app use the same keys but it is not a secure partition. Consider this carefully before storing sensitive information in web storage.
Returns the value of the specified cookie.
Parameters:
Name | Type | Description |
---|---|---|
pName |
string | The name of the cookie. |
Returns:
- Type
- string
Example
var value = apex.storage.getCookie( "TEST" );
Returns a thin wrapper around the localStorage
object that scopes all keys to a prefix defined by the options
parameter. If localStorage is not supported, the returned object can be used but has no effect so it is not necessary test for support using apex.storage.hasLocalStorageSupport before calling this function.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | An object used to define the scope of the local storage. This defines the storage key prefix used by the localStorage wrapper object.
Properties
|
Returns:
- Type
- localStorage
Example
var myStorage,
setting1;
if ( apex.storage.hasLocalStorageSupport() ) {
myStorage = apex.storage.getScopedLocalStorage({ prefix: "Acme" });
myStorage.setItem( "setting1", "on" );
setting1 = myStorage.getItem( "setting1" );
}
Returns a thin wrapper around the sessionStorage
object that scopes all keys to a prefix defined by the options
parameter. If sessionStorage is not supported, the returned object can be used but has no effect so it is not necessary test for support using apex.storage.hasSessionStorageSupport before calling this function.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | An object used to define the scope of the session storage. This defines the storage key prefix used by the sessionStorage wrapper object.
Properties
|
Returns:
- Type
- sessionStorage
Example
var myStorage,
setting1;
if ( apex.storage.hasSessionStorageSupport() ) {
myStorage = apex.storage.getScopedSessionStorage({ prefix: "Acme" });
myStorage.setItem( "setting1", "on" );
setting1 = myStorage.getItem( "setting1" );
}
Returns true
if the browser supports the local storage API and false
otherwise. Most modern browsers support this feature but some allow the user to turn it off.
Returns:
true
if the browser supports the local storage API and false
otherwise.
- Type
- boolean
Example
var myStorage;
if ( apex.storage.hasLocalStorageSupport() ) {
myStorage = apex.storage.getScopedLocalStorage({ prefix: "Acme" });
myStorage.setItem( "setting1", "on" );
}
Returns true
if the browser supports the session storage API and false
otherwise. Most modern browsers support this feature but some allow the user to turn it off.
Returns:
true
if the browser supports the session storage API and false
otherwise.
- Type
- boolean
Example
var myStorage;
if ( apex.storage.hasSessionStorageSupport() ) {
myStorage = apex.storage.getScopedSessionStorage({ prefix: "Acme" });
myStorage.setItem( "setting1", "on" );
}
Sets a cookie to the specified value.
Parameters:
Name | Type | Description |
---|---|---|
pName |
string | The name of the cookie. |
pValue |
String | The value to set the cookie to. |
Example
apex.storage.setCookie( "TEST", "APEX" );
A storage wrapper object. This object has the same properties and functions as the native browser Storage interface.
Properties:
Name | Type | Description |
---|---|---|
prefix |
string | APEX specific property. The prefix for this scoped storage object. |
length |
number | The number of items in the scoped storage object. |
key |
function | The key( n ) function returns the nth key in the scoped storage object. |
getItem |
function | The getItem( key ) function returns the value for the given key. |
setItem |
function | The setItem( key, data ) function sets the value of the given key to data. |
removeItem |
function | The removeItem( key ) function removes the given key. |
clear |
function | The clear function removes all keys from the scoped storage object. |
sync |
function | The APEX specific sync function. Use to ensure the length property is correct if keys may have been added or removed by means external to this object. |