Cache key problem

46 views
Skip to first unread message

Noam Amit

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

we are facing a problem implementing wro4j and using a custom cache key

What we see is the map holding the group entries keeps getting bigger since the cache keys produced have duplicate entries.

Details:

version: 1.7.5
Analysis:
We added a break-point at the following position : MemoryCacheStrategy(line 56)

The map looks like this :

{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}
null
null
{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}
{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}

You can see duplicate enteries although the content is the same(except for the generated hash code.

Here is our implementation of the CacheKeyFactory:



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;
}

}




This causes the system to go OOM

Thanks

Alex Objelean

unread,
Aug 5, 2014, 11:11:36 AM8/5/14
to wr...@googlegroups.com
That is weird. 
The CacheKey hashCode and equals compare all the fields. Expected behavior, is to have unique key containing the same combination of groupName, type and map attributes.
I have created a test to check that adding same key twice, doesn't add two entries to the map. 
Could you create a similar unit test and let me know if you managed to isolate the problem?

Thanks,
Alex


--
You received this message because you are subscribed to the Google Groups "wro4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wro4j+un...@googlegroups.com.
To post to this group, send email to wr...@googlegroups.com.
Visit this group at http://groups.google.com/group/wro4j.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages