All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.mfrey.thymeleaf.extras.cache.CacheEvictProcessor Maven / Gradle / Ivy

Go to download

A dialect for Thymeleaf that allows you to do partial page caching. Some parts of our webpage will never change during the lifetime of the application or a usersession, but the part should still be dynamic in the beginning. Working with Thymeleaf 3.0.0+ (3.0.0.RELEASE and its dependencies included)

There is a newer version: 3.0.1
Show newest version
package ch.mfrey.thymeleaf.extras.cache;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.engine.AttributeName;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
import org.thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor;
import org.thymeleaf.templatemode.TemplateMode;

public class CacheEvictProcessor extends AbstractStandardExpressionAttributeTagProcessor {

    private static final Logger log = LoggerFactory.getLogger(CacheEvictProcessor.class);
    public static final int PRECEDENCE = 9;

    protected CacheEvictProcessor(TemplateMode templateMode, String dialectPrefix) {
        super(templateMode, dialectPrefix, "evict", PRECEDENCE, true);
    }

    @Override
    protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
            String attributeValue,
            Object expressionResult, IElementTagStructureHandler structureHandler) {
        String cacheName = CacheManager.INSTANCE.getCacheNameFromExpressionResult(expressionResult);
        if (cacheName == "") {
            log.debug("Cache eviction name resulted in empty string - ignoring {}", attributeValue);
            return;
        }

        log.debug("Cache eviction for {}", cacheName);
        CacheManager.INSTANCE.evict(cacheName, getTemplateMode(), context.getLocale());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy