diff --git a/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java b/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java index dee8e71823..466ddc7702 100644 --- a/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java @@ -36,6 +36,7 @@ import org.ofbiz.base.util.UtilCodec; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.content.content.ContentWorker; import org.ofbiz.content.content.ContentWrapper; import org.ofbiz.entity.Delegator; @@ -52,6 +53,8 @@ import org.ofbiz.service.LocalDispatcher; public class CategoryContentWrapper implements ContentWrapper { public static final String module = CategoryContentWrapper.class.getName(); + public static final String SEPARATOR = "::"; // cache key separator + private static final UtilCache categoryContentCache = UtilCache.createUtilCache("category.content", true); // use soft reference to free up memory if needed protected LocalDispatcher dispatcher; protected GenericValue productCategory; @@ -92,11 +95,17 @@ public class CategoryContentWrapper implements ContentWrapper { public static String getProductCategoryContentAsText(GenericValue productCategory, String prodCatContentTypeId, Locale locale, String mimeTypeId, Delegator delegator, LocalDispatcher dispatcher, String encoderType) { String candidateFieldName = ModelUtil.dbNameToVarName(prodCatContentTypeId); UtilCodec.SimpleEncoder encoder = UtilCodec.getEncoder(encoderType); + String cacheKey = prodCatContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR + productCategory.get("productCategoryId"); try { + String cachedValue = categoryContentCache.get(cacheKey); + if (cachedValue != null) { + return cachedValue; + } Writer outWriter = new StringWriter(); getProductCategoryContentAsText(null, productCategory, prodCatContentTypeId, locale, mimeTypeId, delegator, dispatcher, outWriter); String outString = outWriter.toString(); if (outString.length() > 0) { + outString = categoryContentCache.putIfAbsentAndGet(cacheKey, encoder.encode(outString)); return encoder.encode(outString); } else { return null; diff --git a/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java b/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java index d209c3bbcb..abd36334fd 100644 --- a/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java @@ -34,6 +34,7 @@ import org.ofbiz.base.util.StringUtil.StringWrapper; import org.ofbiz.base.util.UtilCodec; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.content.content.ContentWorker; import org.ofbiz.content.content.ContentWrapper; import org.ofbiz.entity.Delegator; @@ -52,6 +53,8 @@ import org.ofbiz.service.ServiceContainer; public class ProductConfigItemContentWrapper implements ContentWrapper { public static final String module = ProductConfigItemContentWrapper.class.getName(); + public static final String SEPARATOR = "::"; // cache key separator + private static final UtilCache configItemContentCache = UtilCache.createUtilCache("configItem.content", true); // use soft reference to free up memory if needed protected transient LocalDispatcher dispatcher; protected String dispatcherName; @@ -116,11 +119,17 @@ public class ProductConfigItemContentWrapper implements ContentWrapper { public static String getProductConfigItemContentAsText(GenericValue productConfigItem, String confItemContentTypeId, Locale locale, String mimeTypeId, Delegator delegator, LocalDispatcher dispatcher, String encoderType) { UtilCodec.SimpleEncoder encoder = UtilCodec.getEncoder(encoderType); String candidateFieldName = ModelUtil.dbNameToVarName(confItemContentTypeId); + String cacheKey = confItemContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR + productConfigItem.get("productCategoryId"); try { + String cachedValue = configItemContentCache.get(cacheKey); + if (cachedValue != null) { + return cachedValue; + } Writer outWriter = new StringWriter(); getProductConfigItemContentAsText(null, productConfigItem, confItemContentTypeId, locale, mimeTypeId, delegator, dispatcher, outWriter); String outString = outWriter.toString(); if (outString.length() > 0) { + outString = configItemContentCache.putIfAbsentAndGet(cacheKey, encoder.encode(outString)); return encoder.encode(outString); } else { String candidateOut = productConfigItem.getModelEntity().isField(candidateFieldName) ? productConfigItem.getString(candidateFieldName): "";