Solprovider Lenya Kongregate Registration for Free Flash Games and Chat with solprovider

Disabling Caching for Dynamic Webpages

If your Lenya website is completely static, the automatic caching of the default publication reduces your server load and speeds responses. If your Lenya website has dynamic pages, they may not work with the caching. The usual answer is to disable the caching, and everything slows.

Following these instructions will disable the cache for two types of requests:
1. When a visitor is logged in.
My menus change when a visitor is logged in. The "Login/Registration" link's label changes to "My Page". They can save pages to their Favorites list. If they are an employee, the Employee section appears. If they are a site maintainer, an "Edit" link appears. None of this will happen if they receive a cached page.

2. When the URL has a QueryString.
The QueryString is used for UseCases. It can also be used in any XMAP for deciding how to display a page. The original instructions for dynamically changing the XSL used that method. (See Multiple Stylesheets (Obsolete).) You could also change CSS using a similar method.

A (good) side effect is you can disable the cache for any page by adding "?garbage" to any URL. The garbage can be anything; I typically use a single character: "?d" while testing.

After following these instructions, the cache will only be used for URLs without QueryStrings for visitors who have not logged in. That will at least improve delivery of the homepage, and could help elsewhere.

Instructions


FILE: {pub}/publication-sitemap.xmap
Replace:
<map:match pattern="**.html">
...
</map:match>


With this code:

<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: BEGIN -->
<map:when test="{global:cache-dir}/{../1}.html">
<map:read src="{global:cache-dir}/{../1}.html" mime-type="text/html"/>
</map:when>
<!-- Check Cache: END -->
<map:otherwise>
<map:generate src="cocoon:/{../1}.nocache"/>
<map:match pattern="live/**.html">
<!-- Create Cache: BEGIN -->
<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>
<!-- Create Cache: END -->
<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>


<< External LinksWebsite Map >>

Contact Solprovider
Paul Ercolino