Skip to content

Commit

Permalink
#24247 if ttl is 0 it means no cache, use new StringWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Mar 3, 2023
1 parent 405bdbf commit d5e3580
Showing 1 changed file with 3 additions and 6 deletions.
Expand Up @@ -40,14 +40,14 @@ public boolean render(InternalContextAdapter context, Writer writer, Node node)
HttpServletRequest request = (HttpServletRequest) context.get("request");
boolean shouldCache = shouldCache(request);
boolean refreshCache = refreshCache(request);
if (!shouldCache) {
final int ttl = (Integer) node.jjtGetChild(1).value(context);
if (!shouldCache || ttl <= 0) {
node.jjtGetChild(2).render(context, writer);
return true;
}


final String key = String.valueOf(node.jjtGetChild(0).value(context));
final int ttl = (Integer) node.jjtGetChild(1).value(context);
if (refreshCache) {
CacheLocator.getBlockDirectiveCache().remove(key);
}
Expand All @@ -59,8 +59,7 @@ public boolean render(InternalContextAdapter context, Writer writer, Node node)
return true;
}

final StringWriter blockContent = STRINGWRITER.get();
blockContent.getBuffer().setLength(0);
final StringWriter blockContent = new StringWriter();
node.jjtGetChild(2).render(context, blockContent);
writer.write(blockContent.toString());
CacheLocator.getBlockDirectiveCache().add(key, Map.of(BlockDirectiveCache.PAGE_CONTENT_KEY, blockContent.toString()),
Expand All @@ -74,8 +73,6 @@ protected boolean allowExecution() {
return LicenseManager.getInstance().isEnterprise();
}

private static final ThreadLocal<StringWriter> STRINGWRITER = ThreadLocal.withInitial(StringWriter::new); //NOSONAR


boolean shouldCache(HttpServletRequest request) {
if (request == null) {
Expand Down

0 comments on commit d5e3580

Please sign in to comment.