Skip to content

Commit

Permalink
Implemented: Refactored the ContentWrapper implementations to use the
Browse files Browse the repository at this point in the history
central cache key separator (OFBIZ-10194)
  • Loading branch information
Michael Brohl authored and mbrohl committed Feb 2, 2024
1 parent a2f3ec8 commit 502c56b
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

public interface ContentWrapper {

String MDOULE = ContentWrapper.class.getName();
String MODULE = ContentWrapper.class.getName();
static final String CACHE_KEY_SEPARATOR = "::";

StringUtil.StringWrapper get(String contentTypeId, String encoderType);

Expand Down Expand Up @@ -108,7 +109,7 @@ static String encodeContentValue(String value, String encoderType) {
if (encoder != null) {
value = encoder.sanitize(value, null);
} else {
Debug.logWarning("Unknown encoderType %s for encoding content value!", MDOULE, encoderType);
Debug.logWarning("Unknown encoderType %s for encoding content value!", MODULE, encoderType);
}
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
public class OrderContentWrapper implements ContentWrapper {

private static final String MODULE = OrderContentWrapper.class.getName();
private static final String SEPARATOR = "::"; // cache key separator

private static final UtilCache<String, String> ORDER_CONTENT_CACHE = UtilCache.createUtilCache(
"order.content.rendered", true); // use soft reference to free up memory if needed
Expand Down Expand Up @@ -106,11 +105,11 @@ public static String getOrderContentAsText(GenericValue order, String orderConte
* there was no content to retrieve)
*/
/* caching: there is one cache created, "order.content" Each order's content is cached with a key of
* contentTypeId::locale::mimeType::orderId::orderItemSeqId, or whatever the SEPARATOR is defined above to be.
* contentTypeId::locale::mimeType::orderId::orderItemSeqId, or whatever the CACHE_KEY_SEPARATOR is defined above to be.
*/

String cacheKey = orderContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR + order.get(
"orderId") + SEPARATOR + orderItemSeqId + SEPARATOR + encoderType + SEPARATOR + delegator;
String cacheKey = orderContentTypeId + CACHE_KEY_SEPARATOR + locale + CACHE_KEY_SEPARATOR + mimeTypeId + CACHE_KEY_SEPARATOR + order.get(
"orderId") + CACHE_KEY_SEPARATOR + orderItemSeqId + CACHE_KEY_SEPARATOR + encoderType + CACHE_KEY_SEPARATOR + delegator;
String cachedValue = ORDER_CONTENT_CACHE.get(cacheKey);
if (cachedValue != null || ORDER_CONTENT_CACHE.containsKey(cacheKey)) {
return cachedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
public class PartyContentWrapper implements ContentWrapper {

private static final String MODULE = PartyContentWrapper.class.getName();
public static final String CACHE_KEY_SEPARATOR = "::";

private static final UtilCache<String, String> PARTY_CONTENT_CACHE = UtilCache.createUtilCache("party.content.rendered", true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class CategoryContentWrapper implements ContentWrapper {

private static final String MODULE = CategoryContentWrapper.class.getName();
public static final String SEPARATOR = "::"; // cache key separator

private static final UtilCache<String, String> CATEGORY_CONTENT_CACHE = UtilCache.createUtilCache(
"category.content.rendered", true); // use soft reference to free up memory if needed

Expand Down Expand Up @@ -105,9 +105,9 @@ public static String getProductCategoryContentAsText(GenericValue productCategor
* Look for a previously cached entry (may also be an entry with null value if
* there was no content to retrieve)
*/
String cacheKey = prodCatContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR
String cacheKey = prodCatContentTypeId + CACHE_KEY_SEPARATOR + locale + CACHE_KEY_SEPARATOR + mimeTypeId + CACHE_KEY_SEPARATOR
+ productCategory.get("productCategoryId")
+ SEPARATOR + encoderType + SEPARATOR + delegator;
+ CACHE_KEY_SEPARATOR + encoderType + CACHE_KEY_SEPARATOR + delegator;
String cachedValue = CATEGORY_CONTENT_CACHE.get(cacheKey);
if (cachedValue != null || CATEGORY_CONTENT_CACHE.containsKey(cacheKey)) {
return cachedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
public class ProductConfigItemContentWrapper implements ContentWrapper {

private static final String MODULE = ProductConfigItemContentWrapper.class.getName();
public static final String SEPARATOR = "::"; // cache key separator

private static final UtilCache<String, String> CONFIG_ITEM_CONTENT_CACHE = UtilCache.createUtilCache(
"configItem.content.rendered", true); // use soft reference to free up memory if needed

Expand Down Expand Up @@ -136,8 +136,8 @@ public static String getProductConfigItemContentAsText(GenericValue productConfi
/* Look for a previously cached entry (may also be an entry with null value if
* there was no content to retrieve)
*/
String cacheKey = confItemContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR
+ productConfigItem.get("configItemId") + SEPARATOR + encoderType + SEPARATOR + delegator;
String cacheKey = confItemContentTypeId + CACHE_KEY_SEPARATOR + locale + CACHE_KEY_SEPARATOR + mimeTypeId + CACHE_KEY_SEPARATOR
+ productConfigItem.get("configItemId") + CACHE_KEY_SEPARATOR + encoderType + CACHE_KEY_SEPARATOR + delegator;
String cachedValue = CONFIG_ITEM_CONTENT_CACHE.get(cacheKey);
if (cachedValue != null || CONFIG_ITEM_CONTENT_CACHE.containsKey(cacheKey)) {
return cachedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
public class ProductContentWrapper implements ContentWrapper {

private static final String MODULE = ProductContentWrapper.class.getName();
public static final String SEPARATOR = "::"; // cache key separator

private static final UtilCache<String, String> PRODUCT_CONTENT_CACHE = UtilCache.createUtilCache("product.content.rendered", true);

Expand Down Expand Up @@ -109,12 +108,12 @@ public static String getProductContentAsText(GenericValue product, String produc
* Look for a previously cached entry (may also be an entry with null value if
* there was no content to retrieve) caching: there is one cache created,
* "product.content" Each product's content is cached with a key of
* contentTypeId::locale::mimeType::productId, or whatever the SEPARATOR is
* contentTypeId::locale::mimeType::productId, or whatever the CACHE_KEY_SEPARATOR is
* defined above to be.
*/
String cacheKey = productContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR + product.get(
"productId") + SEPARATOR
+ encoderType + SEPARATOR + delegator;
String cacheKey = productContentTypeId + CACHE_KEY_SEPARATOR + locale + CACHE_KEY_SEPARATOR + mimeTypeId + CACHE_KEY_SEPARATOR + product.get(
"productId") + CACHE_KEY_SEPARATOR
+ encoderType + CACHE_KEY_SEPARATOR + delegator;
String cachedValue = PRODUCT_CONTENT_CACHE.get(cacheKey);
if (cachedValue != null || PRODUCT_CONTENT_CACHE.containsKey(cacheKey)) {
return cachedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
public class ProductPromoContentWrapper implements ContentWrapper {

private static final String MODULE = ProductPromoContentWrapper.class.getName();
public static final String SEPARATOR = "::"; // cache key separator

private static final UtilCache<String, String> PRODUCT_PROMO_CONTENT_CACHE =
UtilCache.createUtilCache("product.promo.content.rendered", true);
Expand Down Expand Up @@ -116,10 +115,10 @@ public static String getProductPromoContentAsText(GenericValue productPromo, Str
* there was no content to retrieve)
*/
/* caching: there is one cache created, "product.promo.content" Each productPromo's content is cached with a key of
* contentTypeId::locale::mimeType::productPromoId, or whatever the SEPARATOR is defined above to be.
* contentTypeId::locale::mimeType::productPromoId, or whatever the CACHE_KEY_SEPARATOR is defined above to be.
*/
String cacheKey = productPromoContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR + productPromo.get("productPromoId")
+ SEPARATOR + encoderType + SEPARATOR + delegator;
String cacheKey = productPromoContentTypeId + CACHE_KEY_SEPARATOR + locale + CACHE_KEY_SEPARATOR + mimeTypeId + CACHE_KEY_SEPARATOR + productPromo.get("productPromoId")
+ CACHE_KEY_SEPARATOR + encoderType + CACHE_KEY_SEPARATOR + delegator;
String cachedValue = PRODUCT_PROMO_CONTENT_CACHE.get(cacheKey);
if (cachedValue != null || PRODUCT_PROMO_CONTENT_CACHE.containsKey(cacheKey)) {
return cachedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
public class WorkEffortContentWrapper implements ContentWrapper {

private static final String MODULE = WorkEffortContentWrapper.class.getName();
public static final String CACHE_KEY_SEPARATOR = "::";

private static final UtilCache<String, String> WORK_EFFORT_CONTENT_CACHE = UtilCache.createUtilCache("workeffort.content.rendered", true);

Expand Down

0 comments on commit 502c56b

Please sign in to comment.