3

My use case is the following: Some of my components must have working action.setStorable ( as the result of their server actions may always be the same , like list of picklist values, so no need to interrogate the server each time )

How can I initialize correctly aura Storage so the cache in the following code is really taken in account ?

initItemsFromSObjectFieldHlp : function(component) {
    var SObjectField = component.get('v.sObjectField');
    var action = component.get("c.listPickListValuesApex");
    action.setParams({'sObjectField': SObjectField }); 
    action.setStorable(); // result is stored in aura cache coz it'll always be the same
    action.setCallback(this, function(response) {
        var items = response.getReturnValue();
        component.set('v.items',items);
    });
    $A.enqueueAction(action);           
}

I struggle with documentation to use aura:storage ( https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_auraStorage_init.htm ) It says Use auraStorage:init to initialize storage in your app’s template for caching server-side action response values. , but just after the example is with a component ...

If i copy-paste the doc example in a component CmpInitStorage that I include in my main component, i see the following error :

<aura:component isTemplate="true" extends="aura:template">
    <aura:set attribute="auraPreInitBlock">
        <!-- Note that the maxSize attribute in auraStorage:init is in KB -->
        <auraStorage:init name="actions" persistent="false" secure="false"
         maxSize="1024" />
    </aura:set>
</aura:component>

included with

<c:CmpInitStorage />

error triggered :

Uncaught SyntaxError: Unexpected token ;

I also tried to add directly in my component or in my main .app but it doesn't work neither

<aura:set attribute="auraPreInitBlock">
    <!-- Note that the maxSize attribute in auraStorage:init is in KB -->
    <auraStorage:init name="actions" persistent="false" secure="false"
     maxSize="1024" />
</aura:set>

1 Answer 1

4

The <aura:component isTemplate="true"/> means the "component" is a template for an app. Check out this documentation - https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apps_template_overview.htm

You need to add the template="c:CmpInitStorage" attribute to your app's <aura:application> tag.

6

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .