You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Yves Zoundi <bi...@hermes.ulaval.ca> on 2006/09/10 00:35:04 UTC
[FIX] I18nTransformer [CACHING PIPELINE]
Hi everybody,
Thanks to Ard, I am able to provide a fix for the I18nTransformer.
THE PROBLEM
My problem was that I am using a session to track the user locale and a
caching pipeline. I am using the LocaleAction to intercept the locale
value via the module session-attr :
<map:act type = "locale">
<map:match pattern = "test.html">
<map:generate src = "test.html"/>
<map:transform type = "i18n">
<map:parameter name = "locale" value = "{session-attr:locale}"/>
</map:transform>
<map:serialize type = "html"/>
</map:match>
</map:act>
NOTE
Without caching(<map:pipeline type='caching'>...</map:pipeline>) the
problem doesn't occur but the performance is poor.
THE SOLUTION
The issue with the i18ntransformer is that generated cache keys are not
unique. A simple solution which might not be the best is:
package org.fix.cocoon.transformation;
import java.io.Serializable;
import org.apache.cocoon.environment.*;
import org.apache.cocoon.transformation.I18nTransformer;
/**
*
* @author Yves Zoundi
*/
public class I18nTransformerFix extends I18nTransformer {
public Serializable getKey() {
StringBuffer buff = new StringBuffer();
buff.append("" + System.currentTimeMillis());
buff.append("_");
buff.append(super.getKey());
return buff.toString();
}
}
It would be good to have a I18nSessionEnabledTransformer so that the cache
keys are always associated to the session. This would also prevent the
i18ntransformer to generate a huge amount of keys.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [FIX] I18nTransformer [CACHING PIPELINE]
Posted by Jason Johnston <co...@lojjic.net>.
Yves Zoundi wrote:
> THE PROBLEM
> My problem was that I am using a session to track the user locale and a
> caching pipeline. I am using the LocaleAction to intercept the locale
> value via the module session-attr :
I don't know if you've seen it, but the Cocoon samples for i18n seem to
do exactly what you're talking about: store the locale in the session
and feed that locale to the i18n transformer, in a caching pipeline.
Here's the samples URL:
http://cocoon.zones.apache.org/demos/release/samples/i18n/
And here's the sitemap they use:
http://cocoon.zones.apache.org/demos/release/samples/i18n/sitemap.xmap
Try out the i18n samples, switching between locales in the left-hand
menu, noticing that the displayed text changes appropriately. Then go
to the system status page:
http://cocoon.zones.apache.org/demos/release/samples/i18n/sitemap.xmap
and notice that there are cache keys that contain something like:
_T-i18n-translations?de_AT_EURO
_T-i18n-translations?es_ES_
_T-i18n-translations?en_US_
etc...
This shows that the contents for each language are cached individually
as they should be.
It sounds to me like you're seeing a symptom of something else unrelated
to the I18nTransformer's caching key. Check out how the i18n samples
are put together and see what you're doing different that may be messing
things up.
--Jason
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [FIX] I18nTransformer [CACHING PIPELINE]
Posted by Jason Johnston <co...@lojjic.net>.
Yves Zoundi wrote:
> THE SOLUTION
> The issue with the i18ntransformer is that generated cache keys are not
> unique. A simple solution which might not be the best is:
...
> public class I18nTransformerFix extends I18nTransformer {
> public Serializable getKey() {
> StringBuffer buff = new StringBuffer();
> buff.append("" + System.currentTimeMillis());
> buff.append("_");
> buff.append(super.getKey());
> return buff.toString();
> }
> }
Whoa... using the current time in the cache key pretty much guarantees
that two calls of getKey() will never return the same value, and
therefore you'll never get a cache hit. This renders caching completely
useless, it's just as if the I18nTransformer were not cacheable at all!
I still don't see why you're having problems to begin with. As long as
the locale is correctly used to build the cache key everything should be
fine and dandy. If something's going wrong with that then I think a
real fix needs to be found rather than adding extra junk to the cache key.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org