cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <coc...@lojjic.net>
Subject Re: [FIX] I18nTransformer [CACHING PIPELINE]
Date Tue, 12 Sep 2006 04:09:25 GMT
I tried out your example code.  And I'm unable to reproduce any improper 
caching by Cocoon.

I do occasionally see the previous language displayed when clicking the 
link to the other test page after a locale switch.  But in all these 
cases it's due to client-side caching; I can verify this because (1) the 
Cocoon log shows either no requests or just the first request in the 
case of the redirect-to, and because (2) a hard-refresh (Ctrl-Shift-R in 
Firefox) to force a server reload always shows the correct language.

One exception to this: a normal refresh (Ctrl-R) sometimes hits the 
server and an access log entry is written, but the content is still not 
updated.  Oh my!  But actually it turns out this is still due to 
client-side caching, because the browser is just issuing an 
If-Modified-Since request and gets a "304 Not Modified" response back. 
This is easily verified by watching the headers with the LiveHTTPHeaders 
Firefox extension.  As soon as the browser issues a request without the 
If-Modified-Since header the new content is downloaded and displayed.

Now, this last case may seem wrong at first glance, since you'd think 
that Cocoon should not respond with a HTTP 304 since the locale has 
changed.  But as far as Cocoon is concerned it *hasn't* changed, since 
it (meaning the current pipeline cache key, complete with the current 
locale) was cached a while ago.  So actually it's perfectly correct for 
Cocoon to return a 304 if the browser asks for it.

I hope this helps explain what you're seeing.  In terms of how to work 
around it, I suppose you could try setting HTTP response headers (e.g. 
with the set-header action) to prevent browser caching, since that seems 
to be the root of the problem.  I'm not sure what headers those would 
need to be.  Let us know if you figure it out, or if you disagree with 
any of my assessment.

--Jason


Yves Zoundi wrote:
> Hi everybody,
> 
>    There is really a bug with the i18ntransformer! If you thing I'm doing
> something wrong with the code below please help!
> 
> My test scenario
> -----------------------------
>    I used an unmodified build of cocoon, no custom exclusions of some
> blocs. I checked again my code based on the samples : copy and paste.
> Guess wwhat? It doesn't work! I am pretty sure about my code, nothing
> special straight from the samples. 
>    I modified the welcome.xml file to include some i18n:text and I created
> a test.html file with some i18n keys. I used the configuration from the
> i18n samples and I believe there is a bug with the i18ntransformer. 
>    I only used the root sitemap.xmap.
> 
> * Here are the relevant parts of the sitemap.xmap
> ...
>  <map:transformer name="i18n" logger="sitemap.transformer.i18n"
> src="org.apache.cocoon.transformation.I18nTransformer">
>  <catalogues default="messages">
>    <catalogue id="messages" name="messages" location="translations"/>
>           <catalogue id="menu" name="menu" location="translations"/>
>           <catalogue id="tiered" name="messages">
>         <location>translations/tiered</location>
>         <location>translations</location>
>       </catalogue>
>  </catalogues>
>         <cache-at-startup>true</cache-at-startup>
>  </map:transformer>
> ...
>  <map:action name="locale" logger="sitemap.action.locale"
> src="org.apache.cocoon.acting.LocaleAction">
>         <!-- Creates a new session if needed. Used with 'store-in-session'
> param -->
>         <create-session>true</create-session>
>         <!-- Stores locale information in session. A session should be
> created before, 
>              otherwise 'create-session' should be true.
>                 -->
>         <store-in-session>true</store-in-session>
>         <!-- Stores locale information in request attributes -->
>         <store-in-request>true</store-in-request>
>         <!-- Stores locale information in a client cookie -->
>         <store-in-cookie>false</store-in-cookie>
>       <default-locale language="en" country="US"/>
>  </map:action>
> 
> ...
>  <!-- main pipeline -->
>   <map:pipeline type = "caching">
>    <map:act type = "locale">    
>     <map:match pattern = "index.html">
> 	<map:redirect-to uri = ""/>
>     </map:match> 
>     <map:match pattern = "status.html">
>        <map:generate type = "status"/>
>        <map:transform src = "stylesheets/system/status2html.xslt"/>
>        <map:serialize type = "html"/>    
>     </map:match>    
>     <map:match pattern = "test.html">
> 	<map:generate src = "test.html"/>
> 	 <map:transform type = "i18n">
> 	 <map:parameter name="locale" value="{../locale}"/>
>       </map:transform>
>       <map:serialize type = "html"/>
>     </map:match> 
>     <!-- welcome page -->
>     <map:match pattern="">
>       <map:generate src="welcome.xml"/>      
>       <map:transform type = "i18n">		 
> 	 <map:parameter name="locale" value="{../locale}"/>
>       </map:transform>
>       <map:transform src="welcome.xslt">
>         <map:parameter name="contextPath" value="{request:contextPath}"/>
>       </map:transform>
>       <map:serialize type="xhtml"/>
>     </map:match>
> </map:act>
> ...
> 
> ...
> 
> Here are the original welcome.xml(customized) and test.html files
> *welcome.xml
> <?xml version="1.0" encoding="UTF-8"?><!--
> <welcome xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
>  <message>
>  <p><i18n:text>francais</i18n:text></p>
>  <p><i18n:text>anglais</i18n:text></p>
>  <p><a href = "test.html">test</a></p>
>    Congratulations! If you are reading this page, it means that
>    your Apache Cocoon installation was successful.
>  </message>
>   <message id="samples">
>    To know more about Cocoon capabilities, look at the <link
> href="samples/">samples</link>
>   </message>  
> </welcome>
> 
> * test.html
> <html xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
>  
> 	<head><title>test</title></head>
> 	<body>
> 	<p><i18n:text>francais</i18n:text></p>
>  <p><i18n:text>anglais</i18n:text></p>
>  <p><a href = "index.html">home</a></p>
> 	
> 	</body>
> </html>
> 
> * messages_en_US.xml
> <catalogue xml:lang="en_US">
>  <message key="anglais">english</message>
>  <message key="francais">french</message>  
> </catalogue>
> 
> * messages_fr_FR.xml
> <catalogue xml:lang="fr_FR">
>  <message key="anglais">anglais</message>
>  <message key="francais">francais</message>  
> </catalogue>
> 
> * messages.xml
> <catalogue xml:lang="fr_FR">
>  <message key="anglais">anglais</message>
>  <message key="francais">francais</message>  
> </catalogue>
> 
> The catalogs are simple with only 2 keys.
> 
> I am switching the languages by manually appending a request parameter
> ?locale=fr_FR or ?locale=en_US to the current URL. Sometimes when I
> navigate between index.html and test.html, I see that the locale is not
> updated, Cocoon is serving the cache without analysing the session locale.
> I tried using the session-attribute generator to see if the locale was
> updated and It is. The cocoon status shows me that the catalog are in the
> cache and the cache keys of the pages(i18ntransformer cache keys) seem all
> right. The keys seem unique for a request.
> 
> Thanks in advance.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message