From 4acd55e90d96538016e1ca850378ab9d57b3bb67 Mon Sep 17 00:00:00 2001 From: remm Date: Wed, 29 Nov 2006 00:30:07 +0000 Subject: [PATCH] - 41057: Caching large strings uses too much memory and is a bit pointless, so add an upper bound to the String length. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@480302 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/buf/StringCache.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/java/org/apache/tomcat/util/buf/StringCache.java b/java/org/apache/tomcat/util/buf/StringCache.java index 50f5b2f04..423fed922 100644 --- a/java/org/apache/tomcat/util/buf/StringCache.java +++ b/java/org/apache/tomcat/util/buf/StringCache.java @@ -56,7 +56,11 @@ public class StringCache { Integer.parseInt(System.getProperty("tomcat.util.buf.StringCache.cacheSize", "200")); - /** + protected static int maxStringSize = + Integer.parseInt(System.getProperty("tomcat.util.buf.StringCache.maxStringSize", "128")); + + + /** * Statistics hash map for byte chunk. */ protected static HashMap bcStats = new HashMap(cacheSize); @@ -210,7 +214,7 @@ public class StringCache { // still training if (bcCache == null) { String value = bc.toStringInternal(); - if (byteEnabled) { + if (byteEnabled && (value.length() < maxStringSize)) { // If training, everything is synced synchronized (bcStats) { // If the cache has been generated on a previous invocation @@ -324,7 +328,7 @@ public class StringCache { // still training if (ccCache == null) { String value = cc.toStringInternal(); - if (charEnabled) { + if (charEnabled && (value.length() < maxStringSize)) { // If training, everything is synced synchronized (ccStats) { // If the cache has been generated on a previous invocation -- 2.11.0