What is the most efficient way to implement this and follow best practices?
A developer wants to improve runtime performance of Apex calls by caching results on the client.
What is the most efficient way to implement this and follow best practices?
A. Call the setStorable () method on the action in the JavaScript client-side code.
B. Set a cookie in the browser for use upon return to the page.
C. Decorate the server-side method with @AuraEnsbled(storable=true).
D. Decorate the server-side method with @AuraZnabled(cacheable=true).
Answer: D
Explanation:
To improve runtime performance by caching Apex call results on the client, the developer should decorate the server-side method with @AuraEnabled(cacheable=true). @AuraEnabled(cacheable=true) Annotation:
When applied to an Apex method, it enables the method’s results to be cached on the client, improving performance for subsequent calls.
This is especially effective in Lightning Web Components (LWC) and can also be used in Aura components.
"To cache method results, annotate the method with @AuraEnabled(cacheable=true). Methods annotated with cacheable=true are called cached methods."
― Lightning Web Components Developer Guide: Call Apex Methods Why Not Other Options:
A. Call the setStorable() method on the action in the JavaScript client-side code: This approach is used in Aura components but is less efficient and not considered best practice compared to using cacheable=true.
"For improved performance, use @AuraEnabled(cacheable=true) instead of action.setStorable()."
― Aura Components Developer Guide: Calling Server-Side Actions
B. Set a cookie in the browser for use upon return to the page: Managing cookies for caching Apex results is not efficient and can lead to security and scalability issues.
C. Decorate the server-side method with @AuraEnabled(storable=true): There is no storable=true parameter for @AuraEnabled. The correct parameter is cacheable=true.
Best Practices:
Use @AuraEnabled(cacheable=true): This is the recommended way to cache Apex method results in Lightning components.
"Apex methods annotated with @AuraEnabled(cacheable=true) are cached on the client and shared across components."
― Lightning Web Components Developer Guide: Apex Methods Cache
Conclusion: By decorating the Apex method with @AuraEnabled(cacheable=true), the developer enables client-side caching of the method’s results, improving runtime performance in an efficient and recommended way.
Latest DEX-450 Dumps Valid Version with 456 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund