How is caching data used in Lightning components?

How is caching data used in Lightning components?

Caching data at the client side can significantly reduce the number of server round-trips and improve the performance of your Lightning components. Using the Lightning Component Framework, you can access server data using either server actions or the Lightning Data Service.

What’s the best way to use Lightning components?

Use the Lightning Data Service or cache data whenever possible (see Data caching). Before making a call to the server, make sure there’s no other option to obtain the data. When appropriate, consider passing data between components using attributes, events, or methods rather than retrieving the same data in different components.

How to disable Salesforce Lightning component caching?

Click through Setup > Session Settings > Caching and deselect Enable secure and persistent browser caching to improve performance. Note that this is an Org-wide setting.

How does the Lightning Data Service help you?

In addition to providing data access, Lightning Data Service caches and synchronizes any data shared by the lightning:record-XXX base components, custom components that use force:recordData, and any standard forms used by Lightning. In Lightning Web Components, there are several ways in which you can take advantage of the Lightning Data Service:

How are server actions used in Lightning components?

Server actions support optional client-side caching, and the Lightning Data Service is built on top of a sophisticated client caching mechanism. In this article, we focus on server actions and explore how to use them to cache the response of server method calls at the client-side and improve the performance of your application.

How does a storable action work in Lightning?

In Lightning terminology, a server action is an Apex method that you invoke remotely from your Lightning Component. A storable action is a server action whose response is stored in the client cache so that subsequent requests for the same server method with the same set of arguments can be accessed from that cache.

What is the maximum age of a cached response in Lightning?

Expiration age: maximum age of the cached response. The cached response is discarded if it is older than the expiration age. In Lightning Experience, the expiration age is currently set to 900 seconds. This value is subject to change, and you can’t change it yourself.

What’s the difference between lightning data service and apex?

Unlike storable actions that can cache any type of response returned by an Apex method, the Lightning Data Service caches discrete Salesforce sObjects (record collections are on the roadmap). You can also implement your own custom cache approach.