+ Start a Discussion
Madhusudan Singh 19Madhusudan Singh 19 

Caching Apex response in lightning aura components

Hi All,

What should I use for caching Apex results in client side. @AuraEnabled(cacheble=true) in apex class or. setStorable in client side?

Regards
Madhusudan Singh
ranbir das 1ranbir das 1
Prior to API version 44.0, to cache data returned from an Apex method, you had to call setStorable() in JavaScript code on every action that called the Apex method.
For API version of 44.0 or higher, you can mark the Apex method as storable (cacheable) and get rid of any setStorable() calls in JavaScript code. The Apex annotation approach is better because it centralizes your caching notation for a method in the Apex class.
so you can use @AuraEnabled(cacheble=true).
mukesh guptamukesh gupta
Hi  Madhusudha,

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.
 
var action = component.get("c.getItems");
action.setStorable();
action.setCallback(this, function(response) {
    // handle response
};
$A.enqueueAction(action);
If this solution is usefull for you, Please mark as a Best Answer to help others.


Regards
Mukesh