Newer Version Available

This content describes an older version of this product. View Latest

Enable Caching of Apex Results

To allow results of Apex calls to be saved for offline use, enable caching on Apex methods used in your offline-enabled mobile apps.

Annotate the Apex method with @AuraEnabled(cacheable=true), which caches the method results on the client. When you set cacheable=true, a method must only retrieve data, it can’t mutate (change) data.

  • Apex methods used in reactive wires must be annotated with @AuraEnabled(cacheable=true), whether you intend to use the results offline or not.
  • Apex methods called imperatively only need to be annotated with @AuraEnabled(cacheable=true) if you want the results to be available offline.

Additional details of Apex method caching behavior and managing cached results can be found in the Lightning Web Components Developer Guide.