Dynamic page caching

The examples given below use the live demo pages here. If you need more time for debugging, download the demo bundle and try this locally, as the demo is periodically restarted.

Dynamic page caching (DPC) instructions step-by-step

The travel demo page template home.yaml can be configured with dynamic navigation. If you want to add dynamic navigation, follow the steps below.

  1. Add the navigation area below to the home.yaml file and publish the changes.

    # ...
    areas:
      navigation:
        fragmentDefinition:
          class: info.magnolia.module.advancedcache.rendering.DynamicFragmentDefinition
          mechanism: sitemesh
      main:
      # ...
  2. Access https://demopublic.magnolia-cms.com/travel so the page is cached.

  3. Select the travel page and click Download cached content in the cache browser.

  4. Inspect the downloaded HTML. This is what you should see:

    ...
    <!-- cms:area content="website:/travel" name="navigation" availableComponents="" type="noComponent" label="Navigation" inherit="false" optional="false" createdAreaNode="false" showAddButton="false" showNewComponentArea="false" activationStatus="2" -->
    <mgnl:injecturi target="/travel/~mgnlArea=navigation~" X-Magnolia-Cache="ttlValue=0,CacheKeyGenerator=,">
    ...
    </mgnl:injecturi><!-- /cms:area -->
    ...
  5. These tags are rendered via the Sitemesh rendering listener referenced by mechanism: sitemesh in the fragment definition.

  6. You can see that the <mgnl:injecturi> tags are replaced by the content of the navigation area when rendering the travel page. The sitemesh filter does that.

How is DPC used for component personalization?

The HTML downloaded in the previous section also contains component personalization.

...
<mgnl:injecturi target="/main/0" X-Magnolia-Cache="ttlValue=-1,">
...
  1. You can see the personalized tour carousel component on this page.

  2. It is rendered via the Personalized component rendering listener.

  3. You should find at least two items for this component in cache browser.

  4. One of those items is downloadable. It is a variant (e.g. for Europe, the Middle East, and Africa) that is inserted into the cached home page instead of the <mgnl:inject> tags if someone, for example, requests the page from Europe.

  5. One of them is just a personalized component marker, and downloading the cache content results in the following error.

    Error while downloading cache content: DefaultCacheKey{uri='/main/0', serverName='demopublic.magnolia-cms.com', locale='en', channel='all', params={}', secure='true', method='get', additionalAttributes='{}'}: Requested cache entry is of type info.magnolia.advancedcache.personalization.cache.PersonalizedCacheEntry …​

Feedback