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:
- User 1 with English as preferred locale, sees detail news article say, news1 in Item Publisher portlet.
- 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:
- Add cache.locale.variation=true to vgnExtTemplating resource
- Add RequestContextModifier to vgn-ext-templating application.
- Register request.context.modifier=yourRequestContextModifier
We will take all these three separately.
- 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.
- 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.
- public class yourReqContextModifier implements RequestContextModifier
- {
- public ReqContextModifier() {}
- public void populate(RequestContext requestContext) throws ApplicationException {
- Locale locale = // Get requested Locale from somewhere
- if (locale == null ){
- locale=Locale.ITALIAN;
- requestContext.setLocale(locale);
- requestContext.setSessionVariable("cdaLocale" , locale);
- }
- else {
- requestContext.setLocale(locale);
- requestContext.setSessionVariable("cdaLocale" , locale);
- }
- }
- }
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.
- Register this RequestContextModifier to vgnExtTemplating resource. For registering it, add request.context.modifier=yourReqContextModifier.