}
public String execute(String previousOut, RenderContext renderContext, Resource resource, RenderChain chain)
throws Exception {
boolean isBinded = resource.getNode().isNodeType("jmix:bindedComponent");
final Script script = (Script) renderContext.getRequest().getAttribute("script");
if (script != null) {
chain.pushAttribute(renderContext.getRequest(), "cache.perUser", Boolean.valueOf(
script.getView().getProperties().getProperty("cache.perUser", "false")));
if(isBinded) {
chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.TRUE);
} else {
chain.pushAttribute(renderContext.getRequest(), "cache.mainResource", Boolean.valueOf(
script.getView().getProperties().getProperty("cache.mainResource", "false")));
}
}
resource.getDependencies().add(resource.getNode().getPath());
String key = cacheProvider.getKeyGenerator().generate(resource, renderContext);
@SuppressWarnings("unchecked")
Set<String> servedFromCache = (Set<String>) renderContext.getRequest().getAttribute("servedFromCache");
if (servedFromCache.contains(key)) {
return previousOut;
}
if (key.contains("_mr_")) {
resource.getDependencies().add(renderContext.getMainResource().getNode().getPath());
if (script != null && Boolean.valueOf(script.getView().getProperties().getProperty(
"cache.mainResource.flushParent", "false"))) {
try {
resource.getDependencies().add(renderContext.getMainResource().getNode().getParent().getPath());
} catch (ItemNotFoundException e) {
}
}
}
boolean cacheable = !notCacheableFragment.contains(key);
if(renderContext.isLoggedIn() && renderContext.getRequest().getParameter("v")!=null){
cacheable = false;
}
if (renderContext.getRequest().getParameter("ec") != null && renderContext.getRequest().getParameter(
"ec").equals(resource.getNode().getIdentifier())) {
cacheable = false;
}
final Cache cache = cacheProvider.getCache();
boolean debugEnabled = logger.isDebugEnabled();
boolean displayCacheInfo = Boolean.valueOf(renderContext.getRequest().getParameter("cacheinfo"));
String perUserKey = key.replaceAll(DefaultCacheKeyGenerator.PER_USER, renderContext.getUser().getUsername()).replaceAll("_mr_",
renderContext.getMainResource().getNode().getPath() +
renderContext.getMainResource().getResolvedTemplate());
/*if (Boolean.TRUE.equals(renderContext.getRequest().getAttribute("cache.dynamicRolesAcls"))) {
key = cacheProvider.getKeyGenerator().replaceField(key, "acls", "dynamicRolesAcls");
chain.pushAttribute(renderContext.getRequest(), "cache.dynamicRolesAcls", Boolean.FALSE);
}*/
if (debugEnabled) {
logger.debug("Generating content for node: {}", perUserKey);
}
try {
if (cacheable) {
String perUser = (String) renderContext.getRequest().getAttribute("perUser");
if (perUser != null) {
// This content must be cached by user as it is defined in the options panel
// The value of the node property from the mixin jmix:cache are only checked in the TemplatesAttributesFilter
// So we need to recalculate the key as we were not aware that this content needed to be cached by user
// We need to store content with the previously calculate dcache to avoid lock up.
cache.put(new Element(perUserKey, null));
key = cacheProvider.getKeyGenerator().replaceField(key, "acls", DefaultCacheKeyGenerator.PER_USER);
perUserKey = key.replaceAll(DefaultCacheKeyGenerator.PER_USER, renderContext.getUser().getUsername()).replaceAll("_mr_",
renderContext.getMainResource().getNode().getPath() +
renderContext.getMainResource().getResolvedTemplate());
}
String cacheAttribute = (String) renderContext.getRequest().getAttribute("expiration");
Long expiration = cacheAttribute != null ? Long.valueOf(cacheAttribute) : Long.valueOf(
script != null ? script.getView().getProperties().getProperty("cache.expiration",
"-1") : "-1");
final Cache dependenciesCache = cacheProvider.getDependenciesCache();
Set<String> depNodeWrappers = resource.getDependencies();
for (String path : depNodeWrappers) {
Element element1 = dependenciesCache.get(path);