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.Arguments;
import org.thymeleaf.dom.Element;
import org.thymeleaf.processor.ProcessorResult;
import org.thymeleaf.processor.attr.AbstractAttrProcessor;

public class CacheEvictProcessor extends AbstractAttrProcessor {
	public static final Logger log = LoggerFactory.getLogger(CacheEvictProcessor.class);
	public static final int PRECEDENCE = 10;

	public CacheEvictProcessor() {
		super("evict");
	}

	@Override
	protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) {
		final String attributeValue = element.getAttributeValue(attributeName);

		element.removeAttribute(attributeName);

		final String cacheName = ExpressionSupport.getEvaluatedAttributeValueAsString(arguments, attributeValue);
		if (cacheName == "") {
			return ProcessorResult.OK;
		}

		CacheManager.evict(arguments, cacheName);

		return ProcessorResult.OK;
	}

	@Override
	public int getPrecedence() {
		return CacheProcessor.PRECEDENCE - 1; // Run just before the CacheProcessor
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy