Newer Version Available

This content describes an older version of this product. View Latest

Storable Actions

Mark an action as storable to have its response stored in the client-side cache by the framework. Caching can be useful if you want your app to be functional for devices that temporarily don’t have a network connection.

A storable action might result in no call to the server. Never mark as storable an action that updates or deletes data.

Warning

Successful actions, for which getState() in the JavaScript callback returns SUCCESS, are stored.

If a storable action is aborted after it’s been sent but not yet returned from the server, its return value is still added to storage but the action callback is not called.

The action response of a storable action is saved in an internal framework-provided storage named actions. This stored response is returned on subsequent calls to the same server-side action instead of the response from the server-side controller, as long as the stored response hasn't expired.

For storable actions in the cache, the framework returns the cached response immediately and also tries to refresh the data for quick display the next time it’s requested. Therefore, storable actions might have their callbacks invoked more than once: first with cached data, then with updated data from the server.

Warning

If the stored response has reached its expiration time, a new response is retrieved from the server-side controller and is stored in the actions storage for subsequent calls.

Enable Storable Actions for Apps

Server-side actions storage is the only currently supported type of storage. Storage for server-side actions caches action response values. The storage name must be actions.

For an example of initializing storage for an app, see Initializing Storage Service.

Marking Storable Actions

To mark a server-side action as storable, call setStorable() on the action in JavaScript code, as follows.

1action.setStorable();

Storable actions are always implicitly marked as abortable too.

Note

The setStorable function takes an optional parameter, which is a configuration map of key-value pairs representing the storage options and values to set. You can only set the following property:

ignoreExisting
Set to true to refresh the stored item with a newly retrieved value, regardless of whether the item has expired or not. The default value is false.

To set the storage options for the action response, pass this configuration map into setStorable().

Refreshing an Action Response for Every Request

To ignore existing stored responses, set:

1action.setStorable({
2    "ignoreExisting": "true"
3});