TransWikia.com

Platform Cache and default partition

Salesforce Asked on October 4, 2021

I am implementing the platform cache for first time.

My query in below snippent is taking lot of time so I want to put the query result in cache/

if(Cache.Org.contains('cvList')){
    for (contentVersion cv: (List<contentVersion>)Cache.Org.get('cvList') ) {
        //do something   
    }
}
else {
    List<contentVersion> cvList = [SELECT Id, ContentDocumentId, Title, FeaturedContentBoost, FileType, File_Size__c,
                                   FileExtension, LastModifiedDate FROM ContentVersion WHERE Id IN: ContentVersionIdSet ORDER BY LastModifiedDate DESC LIMIT 999];
    Cache.Org.put('cvList', cvList);   
    for (contentVersion cv: cvList) {
        //do something
        
    }
}

Q: Is it required to create partition to utilize org cache? I am not getting any compile error but wanted to know if I am doing it correctly

One Answer

If you do not specify the partition it simply means default partition will be used.

I suggest to create a partition and have it as default. Having a default partition is required for the short hand syntax you are using. The syntax you have currently assumes you have default partition in the org and it short hand syntax. You don’t need the fully qualified name if you use the Org.Cache class

As per documentation

If no default partition is specified in the org, calling a cache method without fully qualifying the key name causes a Cache.Org.OrgCacheException to be thrown.

Note this exception will be a run time exception and you won’t see unless the code is executed.

Correct answer by Mohith Shrivastava on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP