Share Your Experience With Others

What happens when you declare method as cacheable=true?

When you set the “cacheable” attribute to “true”, Salesforce caches the response from your Apex method.

The “@wire” decorator in Lightning Web Components (LWC) is used to read data from Salesforce servers.

If you have multiple components on a page that all call the same Apex method with the same parameters, Salesforce only sends a single request to the server.

The response from this request is stored in the client cache, and it’s used for all components that made this call.

If multiple instances of an LWC component are present on a single page, and they all are using the same apex method and sending “recordId” to the component, Salesforce only makes a single server call to get the record details.

The response is then cached and used for all the instances of that LWC component.

This feature helps you reduce the server load and increase the performance of your Lightning Web Components.

Remember that if a method is cacheable, it must only get data. It can’t mutate data. And only read operations are allowed, not create, update, or delete operations (DML operations aren’t allowed).

Leave a comment