Making DPM caching locale specific

Issue Statement:

In case of Item Publisher portlet, DPM caches whole HTML fragment. This caching is not locale specific. This creates in-consistent content in multi-lingual site. Consider the scenario below:

  1. User 1 with English as preferred locale, sees detail news article say, news1 in Item Publisher portlet.
  2. When User 2 with Swedish as preferred locale, sees detail of same news article, news1, DPM get that fragment from cache which is in English version.

Resolution:

To resolve this issue, we need to do three things:

  1. Add cache.locale.variation=true to vgnExtTemplating resource
  2. Add RequestContextModifier to vgn-ext-templating application.
  3. Register request.context.modifier=yourRequestContextModifier

We will take all these three separately.

  1. Add cache.locale.variation=true to vgnExtTemplating resource : The cache.locale.variation config parameter tells DPM to add locale found in the request to cache key. This makes caching locale specific. But, it cached based on RequestContext.getLocale() which appears to be browser locale setting. This creates a problem if user have option to select language on your site, which is usually there in case of multi-lingual site.
  2. To resolve above issue, implement custom RequestContextModifer for DPM application which intercepts every request sent to DPM application and put user's preferred locale to RequestContext.

I am giving a dummy RequestContextModifier, which may change depending upon your locale implementation in your site.

  1. public   class  yourReqContextModifier  implements  RequestContextModifier  
  2. {  
  3.     public  ReqContextModifier() {}  
  4.    
  5.     public   void  populate(RequestContext requestContext)  throws  ApplicationException {  
  6.      Locale locale = // Get requested Locale from somewhere   
  7.         if  (locale ==  null ){  
  8.             locale=Locale.ITALIAN;  
  9.             requestContext.setLocale(locale);  
  10.             requestContext.setSessionVariable("cdaLocale" , locale);  
  11.         }  
  12.         else  {  
  13.       requestContext.setLocale(locale);  
  14.             requestContext.setSessionVariable("cdaLocale" , locale);  
  15.         }  
  16.     }  

Compile this class and put it in vgn-ext-templating.war and deploy that new vgn-text-templating.war file to your application server hosting portal.

  1. Register this RequestContextModifier to vgnExtTemplating resource. For registering it, add request.context.modifier=yourReqContextModifier.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章