Advertisement
Guest User

SE Platform Cache Structure

a guest
Jan 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1. //wrapper class that is used in the cache
  2. global class MenuWrapper{        
  3.     public List<FieloEE__Section__c> sections {get; set;}
  4.     public Map<Id,List<FieloEE__Section__c>> componentsSection {get; set;}
  5.     public Map<Id,FieloEE__Component__c> componentsMap {get; set;}
  6.     public Set<Id> componentCacheIds;
  7. }
  8.  
  9. //Action method
  10. public PageReference init(){    
  11.     loadSections();        
  12.     return null;
  13. }
  14.  
  15. private void loadSections(){        
  16.     //verifies if the cache functionality is enabled
  17.     cacheEnabled = FieloEE__PublicSettings__c.getOrgDefaults().CacheEnabled__c;
  18.     if(cacheEnabled != null && cacheEnabled){
  19.         loadSectionsWithCache();            
  20.     }else{
  21.         loadSectionsWithoutCache();
  22.     }
  23.  
  24. }
  25.  
  26. private void loadSectionsWithoutCache(){    
  27.     //instantiate wrapper class
  28.     menuWrapper = new MenuWrapper();
  29.    
  30.     //queries sections
  31.     menuWrapper.sections = [SELECT Id FROM FieloEE__Section__c WHERE FieloEE__Menu__c =: menu2.Id];
  32.    
  33.     //query subsections with components related lists
  34.     List<FieloEE__Section__c> sections = menuWrapper.sections;
  35.     for(FieloEE__Section__c subSection : Database.query('SELECT Id(SELECT Id FROM FieloEE__Components__r) FROM FieloEE__Section__c WHERE FieloEE__Parent__c IN : sections')){
  36.         //store each subsection in the wrapper
  37.         componentsSection.put(...);
  38.  
  39.         //store components in the wrapper
  40.         componentsMap.put(...);
  41.     }
  42.     //the componentCacheIds is null due cache is inactive
  43. }
  44.  
  45. private void loadSectionsWithCache(){            
  46.     //Get platform cache partition
  47.     orgPart = Cache.Org.getPartition('local.FieloMenus');
  48.    
  49.     //get value from the cache for the current menu Id
  50.     menuWrapper = (MenuWrapper)orgPart.get(menu.Id);
  51.    
  52.     //checks if the key exists in the cache, if no then loads the wrapper
  53.     if(menuWrapper == null){
  54.         loadMenuWrapper(menu.Id);
  55.     }
  56. }
  57.  
  58. private void loadMenuWrapper(String keyString){    
  59.     //instantiates the wrapper
  60.     menuWrapper = new MenuWrapper();
  61.    
  62.     //query sections
  63.     menuWrapper.sections = [SELECT Id FROM FieloEE__Section__c WHERE FieloEE__Menu__c =: menu2.Id];
  64.  
  65.     //query subsections
  66.     for(FieloEE__Section__c subSection : Database.query('SELECT Id (SELECT Id FROM FieloEE__Components__r) FROM FieloEE__Section__c WHERE FieloEE__Parent__c IN : sectionsList AND FieloEE__Parent__r.F_PRM_Asynchronous__c = false')){        
  67.         //store each subsection in the wrapper
  68.         componentsSection.put(...);
  69.  
  70.         //store components in the wrapper
  71.         componentsMap.put(...);
  72.        
  73.         //stores in the wrapper set the component Ids that are set to be cached (content cache)
  74.         for(FieloEE__Component__c c : subSection.FieloEE__Components__r){
  75.             if(c.Cached__c){
  76.                 menuWrapper.componentCacheIds.add(c.Id);
  77.             }
  78.         }
  79.     }
  80.  
  81.     //save the wrapper into the cache
  82.     orgPart.put(keyString,menuWrapper);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement