Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //wrapper class that is used in the cache
- global class MenuWrapper{
- public List<FieloEE__Section__c> sections {get; set;}
- public Map<Id,List<FieloEE__Section__c>> componentsSection {get; set;}
- public Map<Id,FieloEE__Component__c> componentsMap {get; set;}
- public Set<Id> componentCacheIds;
- }
- //Action method
- public PageReference init(){
- loadSections();
- return null;
- }
- private void loadSections(){
- //verifies if the cache functionality is enabled
- cacheEnabled = FieloEE__PublicSettings__c.getOrgDefaults().CacheEnabled__c;
- if(cacheEnabled != null && cacheEnabled){
- loadSectionsWithCache();
- }else{
- loadSectionsWithoutCache();
- }
- }
- private void loadSectionsWithoutCache(){
- //instantiate wrapper class
- menuWrapper = new MenuWrapper();
- //queries sections
- menuWrapper.sections = [SELECT Id FROM FieloEE__Section__c WHERE FieloEE__Menu__c =: menu2.Id];
- //query subsections with components related lists
- List<FieloEE__Section__c> sections = menuWrapper.sections;
- 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')){
- //store each subsection in the wrapper
- componentsSection.put(...);
- //store components in the wrapper
- componentsMap.put(...);
- }
- //the componentCacheIds is null due cache is inactive
- }
- private void loadSectionsWithCache(){
- //Get platform cache partition
- orgPart = Cache.Org.getPartition('local.FieloMenus');
- //get value from the cache for the current menu Id
- menuWrapper = (MenuWrapper)orgPart.get(menu.Id);
- //checks if the key exists in the cache, if no then loads the wrapper
- if(menuWrapper == null){
- loadMenuWrapper(menu.Id);
- }
- }
- private void loadMenuWrapper(String keyString){
- //instantiates the wrapper
- menuWrapper = new MenuWrapper();
- //query sections
- menuWrapper.sections = [SELECT Id FROM FieloEE__Section__c WHERE FieloEE__Menu__c =: menu2.Id];
- //query subsections
- 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')){
- //store each subsection in the wrapper
- componentsSection.put(...);
- //store components in the wrapper
- componentsMap.put(...);
- //stores in the wrapper set the component Ids that are set to be cached (content cache)
- for(FieloEE__Component__c c : subSection.FieloEE__Components__r){
- if(c.Cached__c){
- menuWrapper.componentCacheIds.add(c.Id);
- }
- }
- }
- //save the wrapper into the cache
- orgPart.put(keyString,menuWrapper);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement