Cache Object hashing problem

12 views
Skip to first unread message

noama...@gmail.com

unread,
Aug 5, 2014, 7:32:58 AM8/5/14
to wr...@googlegroups.com
Hi,

We are having problems with our implementation of wro4j

We had to change the groupName in the cacheKey to support our configurable css structure

But when we look at the actual Map storing the keys/values we see duplicates meaning the object attributes are identical but the hash key is different


More details:

version :1.7.5

BreakPoint at: MemoryCacheStrategy (line 56) when observing the map object we get the following output:

{ro.isdc.wro.cache.CacheKey@4ae8f929[
  type
=JS
  groupName
=primo_library_web
  minimize
=false
  map
={}
]=hash: 76bfa243316aa083f53c71c1305cd838e9079f35, ro.isdc.wro.cache.CacheKey@38870b41[
  type
=JS
  groupName
=primo_library_web
  minimize
=true
  map
={}
]=hash: db778d83d4e85805862b1de5b749624be98d8f01, ro.isdc.wro.cache.CacheKey@207c00fb[
  type
=CSS
  groupName
=primo_library_cssen_USAuto1
  minimize
=true
  map
={}
]=hash: 28a5ac0da42bdcc36add114b191793b54d145467, ro.isdc.wro.cache.CacheKey@618901d5[
  type
=JS
  groupName
=primo_library_cssen_USAuto1
  minimize
=true
  map
={}
]=hash: 64a9c7181c32e30a94ff658a7b96705cc6d7ed0a}


 
Notice that there are 2 entries for primo_library_web which are identical except for the hash

This, of course, causes the map to grow and grow extensively until the system is  OOM


Our implementation overrides the CacheKeyFactory in the following manner:






public class PrimoWroCacheKeyFactory implements CacheKeyFactory {
@Inject
private GroupExtractor groupExtractor;

/**
* This method is important because there are some groups that their names are Loacle based. 
* @see PrimoWroModelFactory#create()
* @see PrimoWroModelFactory#createCssGroups(javax.servlet.http.HttpSession, HttpServletRequest, java.util.List, java.util.List)
*/
@Override
public CacheKey create(HttpServletRequest request) {
notNull(request);
CacheKey key = null;
String groupName = groupExtractor.getGroupName(request);
final ResourceType resourceType = groupExtractor
.getResourceType(request);
// if(ResourceType.CSS == resourceType){  
if(groupName != null && groupName.startsWith("primo_library_css")){
//makes sure the cache is built differently for languages -- only css
groupName = PrimoWroUtility.generatePrimoCacheKey(groupName,request);
}
final boolean minimize = groupExtractor.isMinimized(request); 
if (groupName != null && resourceType != null) {
key = new CacheKey(groupName, resourceType, minimize);
}
return key;
}

}



public class PrimoWroUtility {
public static String generatePrimoCacheKey(String wroKey,HttpServletRequest request){
String locale = SessionUtils.resolveLocale(request.getSession(), request); 
String primoViewId = SessionUtils.getPrimoView(request).getId();
return generatePrimoCacheKey(wroKey,locale,primoViewId);
}
public static String generatePrimoCacheKey(String wroKey,String locale, String primoViewId){
return wroKey += locale += primoViewId;
}

}





Can you shed some light on this issue?

Thanks

Noam
Reply all
Reply to author
Forward
0 new messages