ch.mfrey.thymeleaf.extras.cache.TTLCacheValidityChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thymeleaf-cache-dialect Show documentation
Show all versions of thymeleaf-cache-dialect Show documentation
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)
package ch.mfrey.thymeleaf.extras.cache;
import java.util.List;
import org.thymeleaf.cache.ICacheEntryValidityChecker;
import org.thymeleaf.dom.Node;
class TTLCacheValidityChecker implements ICacheEntryValidityChecker> {
/**
*
*/
private static final long serialVersionUID = 1L;
private final int cacheTTLs;
public TTLCacheValidityChecker(int cacheTTLs) {
super();
this.cacheTTLs = cacheTTLs;
}
public boolean checkIsValueStillValid(String key, List value, long entryCreationTimestamp) {
final long currentTimeInMillis = System.currentTimeMillis();
return (currentTimeInMillis < entryCreationTimestamp + this.cacheTTLs * 1000);
}
}