2

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

3

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.

| improve this answer | |
  • Yes, you are right I got the run time exception that default partition is missing. Thanks – C0DEPirate Jul 18 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.