Performance Best Practices for Lightning Component Development

https://developer.salesforce.com/blogs/developer-relations/2017/03/lightning-components-best-practices-caching-data-storable-actions.html

Single record   :  Lightning Data Service

Lightning Data Service を使用すると、Apex コードを必要とせずに、コンポーネントでレコードの読み込み、作成、編集、削除ができます。Lightning データサービスは、共有ルールと項目レベルセキュリティを処理します。Salesforce データへのアクセスを簡素化するだけでなく、Lightning データサービスはパフォーマンスとユーザインターフェースの一貫性を改善します。

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    <aura:attribute name="recordId" type="String" />
    <lightning:recordForm recordId="{!v.recordId}" 
                          objectApiName="Account"
                          mode="readonly"
                          fields="Name, Industry" />

 

 

Collections of records,custom data structures : Storable Actions

アクションを保存可能 (キャッシュ可能) としてマークすると、サーバとの往復を待たずにクライアント側ストレージのキャッシュデータをすばやく表示できるようになり、コンポーネントのパフォーマンスが向上します。

API バージョン 44.0 以上のコンポーネントの Apex メソッドから返されるデータをキャッシュするには、Apex メソッドに @AuraEnabled(cacheable=true) アノテーションを付加する必要があります

@AuraEnabled(cacheable=true)
public static Account getAccount(Id accountId) {
    // your code here
}

Complete control over caching implementation : Custom cache

静的リソースに追加する
window.counter = (function(){

    var Cache= {}; // private

    return { //public API
        
        setDate: function(name, data) {
            Cache[name] = data;
        },

        getData: function(name) {
            return Cache[name];
        }
    };
}());

afterScriptLoaded : function(component, event, helper){

    var sectors = window.DataCache.getFata("sectors");

  if(sectors){

    component.set("v.sectors", sectors);

  }else{

    helper.loadSectors(component);

  }

}

posted @ 2019-12-28 19:25  dlywang0411  阅读(74)  评论(0)    收藏  举报