Storable actions

In Chapter 3Lightning Component Building Blocks, you learned that, to make a call to a server (using the Apex method) from the Lightning Component client-side controller/helper function, we can enqueue an action, using the following code snippet:

var action = component.get("c.getResults");
action.setCallback(this, function(response) {
// handle response
};
$A.enqueueAction(action);

In the code snippet, whenever an action is invoked via events (onInit, click, or custom events), the client makes a call to get the latest data or performs data manipulation (DML), such as the creating, deleting, or editing of records.

This framework provides the ability to mark an action as storable. To mark an action as storable, the code snippet is as follows (pay special attention to the highlighted line):

var action = component.get("c.getResults");
action.setStorable();
action.setCallback(this, function(response) {
// handle response
};
$A.enqueueAction(action);

When an action is marked storable, the results are cached locally for an expiration time (this is  not configurable at this point and is fixed at 900 seconds in the framework). Every 30 seconds, a background action is triggered to get the latest data. 

To learn more about how Lightning Component caching works on storable actions, refer to the blog by Salesforce at https://developer.salesforce.com/blogs/developer-relations/2017/03/Lightning-components-best-practices-caching-data-storable-actions.html.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.141.115