Jahia Dev Forum > Cache for template...

0 (0 Good)
0 (0 Bad)

Cache for template render filter

by  fabu »  2014/01/06 09:56

Hi,

I'm working with Jahia 6.6.2.2 and I would like to cache render filter result.

I read that page: http://www.jahia.com/community/documentation/jahiapedia/jahia-modules/renderingFilter.html

In my spring xml, when I set a priority to a number under 15, result is computed each time.

But when I set a priority above 15, result is computed for the first time, and after, it isn't displayed. Result isn't  in cache.

<bean name="esigateRenderFilter" class="my.package.filters.ESIGateFilter">
    <property name="description" value="[...]"/>
    <property name="priority" value="99"/>
    <property name="applyOnModes" value="live,preview" />
    <property name="applyOnMainResource" value="true"/>
</bean>
And my filter class:
package my.package.filters;
 
import my.package.services.EsiService;
import net.htmlparser.jericho.*;
import org.apache.commons.lang.StringUtils;
import org.esigate.tags.TemplateRenderer;
import org.jahia.services.render.RenderContext;
import org.jahia.services.render.Resource;
import org.jahia.services.render.filter.AbstractFilter;
import org.jahia.services.render.filter.RenderChain;
import org.slf4j.Logger;
 
import java.io.StringWriter;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
 
public class ESIGateFilter extends AbstractFilter {
 
  private transient static Logger logger = org.slf4j.LoggerFactory.getLogger(ESIGateFilter.class);
    
  private static final String startTag = "esigate:meta";
 
  @Override
  public String execute(String previousOut, RenderContext renderContext, Resource resource, RenderChain chain) throws Exception {
 
    // Jericho source from html 
    Source source = new Source(previousOut);
 
    List<StartTag> esiResourceTags = source.getAllStartTags(startTag);
    logger.debug("looking for esigate tags on page = " + Arrays.toString(esiResourceTags.toArray()));
    
    if (resource.getContextConfiguration().equals("page")) {
    
      for (StartTag esiResourceTag : esiResourceTags) {
        
        for (Attribute attribute : esiResourceTag.getAttributes()) {
          
          String esiResourceTagKey = attribute.getKey();
          String esiResourceTagValue = attribute.getValue();
  
          if (esiResourceTagKey.equalsIgnoreCase("remoteUrlBase") && !StringUtils.isBlank(esiResourceTagValue)) {
 
            StringWriter stringWriter = new StringWriter();
            
            // DO STUFF
            
            // clean all esigate:meta tags
            List<StartTag> allStartTags = finalSource.getAllStartTags(startTag);
            for (StartTag startTagToRemove : allStartTags) {
              outputDocument.replace(startTagToRemove,"");
              logger.debug("remove startTag from source = " + startTagToRemove);
            }
            
            return outputDocument.toString().trim();
          }
        }
      }
    }
    return previousOut;
  }
}
 
Please tell me if I did something wrong.
Thanks in advance,
Kind Regards.
 

  (fabu)

Number of messages  28
Registration date
0 (0 Good)
0 (0 Bad)

Re: Cache for template render filter

by  shyrkov »  2014/01/28 21:17

Hello,

 

you could check the rendering filter chain and priorities of the installed filters in the Jahia Tools Area -> Render filters ( http://localhost:8080/tools/renderFilters.jsp )

If your filter has a priority lower than the priority of the AdvancedAggregateCacheFilter than it will be executed (based on the configuration) each time.

You could test in preview mode, where AdvancedAggregateCacheFilter is not effective to "bypass" the Jahia output caches for troubleshooting.

 

Kind regards

Sergiy

  • Re: Cache for template render filter
    2014/01/28 21:17

    shyrkov <p> Hello,</p> <p> &nbsp;</p> <p> you could check the rendering filter chain and priorities of the installed filters in the Jahia Tools Area -&gt; Render filters ( http://localhost:8080/tools/renderFilters.jsp )</p> <p> If your filter has a priority lower than the priority of the AdvancedAggregateCacheFilter than it will be executed (based on the configuration) each time.</p> <p> You could test in preview mode, where AdvancedAggregateCacheFilter is not effective to &quot;bypass&quot; the Jahia output caches for troubleshooting.</p> <p> &nbsp;</p> <p> Kind regards</p> <p> Sergiy</p>

  • Number of messages  407
    Registration date Jan 28, 2014
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page