Bug 35407 - [PATCH] Disable caching if loggedIn or has querystring
Summary: [PATCH] Disable caching if loggedIn or has querystring
Status: NEW
Alias: None
Product: Lenya
Classification: Unclassified
Component: Default Publication (show other bugs)
Version: 1.2.2
Hardware: All All
: P2 enhancement
Target Milestone: 2.0.1
Assignee: Lenya Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-18 01:57 UTC by solprovider
Modified: 2007-07-16 02:39 UTC (History)
0 users



Attachments
disables browser and proxy caching in the authoring area, so that users see their changes immediately. (760 bytes, patch)
2006-05-19 08:36 UTC, J
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description solprovider 2005-06-18 01:57:26 UTC
> Gregor J. Rothfuss wrote "The naive caching with the work directory makes this
[dynamic pages] impossible. In my opinion, it should be removed from lenya."
On 6/17/05, Michael Wechner wrote, "In productive environments with heavy load
it's very useful.  Why don't we just DISABLE it by default instead of removing it?"

Caching seems very useful, but is incompatible with dynamic sites.  Disable it when:
1. A visitor is logged in.  (My menus change when a visitor logs in.)
2. There is a querystring (for Usecases and other fun.  Imagine if the Search
page was cached so the same results showed for any request.)

That leaves regular URLs for non-loggedIn visitors.  That will at least speed
the homepage, and may help elsewhere.

In publication-sitemap.xmap, replace:
<map:match pattern="**.html">
...
</map:match>

With:

<map:match pattern="**.nocache">
   <map:generate
src="cocoon:/lenyabody-view/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-url}"/>
     <map:match pattern="authoring/**.nocache">
        <map:transform
src="cocoon://lenya-page/{page-envelope:publication-id}/{../1}.xml?doctype={page-envelope:document-type}"/>
     </map:match>
     <map:transform src="../../xslt/util/strip_namespaces.xsl"/>
     <map:match pattern="live/**.nocache">
         <map:transform src="../../xslt/authoring/edit/addSourceTags.xsl">
             <map:parameter name="source" value="{global:cache-dir}/live/{1}.html"/>
         </map:transform>
         <map:transform type="write-source">
             <map:parameter name="serializer" value="html-no-dtd"/>
         </map:transform>
         <map:transform src="../../xslt/authoring/edit/removeSourceTags.xsl"/>
      </map:match>
   <map:serialize type="xml"/>
</map:match>

<map:match pattern="**.html">
   <map:act type="language-exists">
      <!-- Is visitor logged in? -->
      <map:select type="parameter">
         <map:parameter name="parameter-selector-test"
value="{access-control:user-id}"/>
         <map:when test="">
         </map:when>
        <map:otherwise>
           <map:generate src="cocoon:/{../1}.nocache"/>
           <map:serialize type="html"/>
        </map:otherwise>
      </map:select>
      <!-- Has querystring? -->
      <map:select type="parameter">
         <map:parameter name="parameter-selector-test"
value="{request:queryString}"/>
         <map:when test="">
         </map:when>
        <map:otherwise>
           <map:generate src="cocoon:/{../1}.nocache"/>
           <map:serialize type="html"/>
        </map:otherwise>
      </map:select>
      <map:select type="resource-exists">
        <!-- Check Cache -->
        <map:when test="{global:cache-dir}/{../1}.html">
           <map:read src="{global:cache-dir}/{../1}.html" mime-type="text/html"/>
        </map:when>
        <map:otherwise>
           <map:generate src="cocoon:/{../1}.nocache"/>
           <map:serialize type="html"/>
        </map:otherwise>
      </map:select>
   </map:act>
   <!-- There is no version of the requested document-id for the requested
language. -->
   <map:generate type="serverpages"
src="../../content/exception/missing-language.xsp"/>
   <map:transform src="../../xslt/exception/missing-language.xsl"/>
   <map:call resource="style-cms-page"/>
</map:match>

This has been alpha tested.  There were a few changes from the user-ML post. 
Someone else should test before committing.

solprovider
Comment 1 solprovider 2005-06-18 23:28:31 UTC
Moved writeToCache to only happen if the document was expected in the cache. 
Prevents security hole if the first visitor to a webpage does not use the cache.

<map:match pattern="**.nocache">
   <map:generate
src="cocoon:/lenyabody-view/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-url}"/>
     <map:match pattern="authoring/**.nocache">
        <map:transform
src="cocoon://lenya-page/{page-envelope:publication-id}/{../1}.xml?doctype={page-envelope:document-type}"/>
     </map:match>
     <map:transform src="../../xslt/util/strip_namespaces.xsl"/>
   <map:serialize type="xml"/>
</map:match>

<map:match pattern="**.html">
   <map:act type="language-exists">
      <!-- Is visitor logged in? -->
      <map:select type="parameter">
         <map:parameter name="parameter-selector-test"
value="{access-control:user-id}"/>
         <map:when test="">
         </map:when>
        <map:otherwise>
           <map:generate src="cocoon:/{../1}.nocache"/>
           <map:serialize type="html"/>
        </map:otherwise>
      </map:select>
      <!-- Has querystring? -->
      <map:select type="parameter">
         <map:parameter name="parameter-selector-test"
value="{request:queryString}"/>
         <map:when test="">
         </map:when>
        <map:otherwise>
           <map:generate src="cocoon:/{../1}.nocache"/>
           <map:serialize type="html"/>
        </map:otherwise>
      </map:select>
      <map:select type="resource-exists">
        <!-- Check Cache -->
        <map:when test="{global:cache-dir}/{../1}.html">
           <map:read src="{global:cache-dir}/{../1}.html" mime-type="text/html"/>
        </map:when>
        <map:otherwise>
           <map:generate src="cocoon:/{../1}.nocache"/>
     <map:match pattern="live/**.html">
         <map:transform src="../../xslt/authoring/edit/addSourceTags.xsl">
             <map:parameter name="source" value="{global:cache-dir}/live/{1}.html"/>
         </map:transform>
         <map:transform type="write-source">
             <map:parameter name="serializer" value="html-no-dtd"/>
         </map:transform>
         <map:transform src="../../xslt/authoring/edit/removeSourceTags.xsl"/>
      </map:match>
           <map:serialize type="html"/>
        </map:otherwise>
      </map:select>
   </map:act>
   <!-- There is no version of the requested document-id for the requested
language. -->
   <map:generate type="serverpages"
src="../../content/exception/missing-language.xsp"/>
   <map:transform src="../../xslt/exception/missing-language.xsl"/>
   <map:call resource="style-cms-page"/>
</map:match>
Comment 2 J 2006-05-19 08:36:54 UTC
Created attachment 18321 [details]
disables browser and proxy caching in the authoring area, so that users see their changes immediately.
Comment 3 J 2006-05-19 12:23:52 UTC
(In reply to comment #2)
> Created an attachment (id=18321) [edit]
> disables browser and proxy caching in the authoring area, so that users see
> their changes immediately.

sorry, this attachment was meant for bug #38723.