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.

    Removing the mgnl:injecturi tag

    If you want to remove the mgnl:injecturi tag, then:

    • Remove the /server/rendering/engine/listeners/personalizedComponent.

    • Set /modules/cache/config/contentCaching/defaultPageCache/cachePolicy@includePersonalizedDescendants to true.

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
    ...

Component is both dynamic and personalized

Since Magnolia 6.2.29, injecting of a component variant tag is disabled when the component is both dynamic and personalized.

The component then fully depends on the tag injected for the dynamic fragment. This works correctly only with TTL set to 0. Any other setting can lead to unpredictable behaviour.

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules