cache

Keyhole caching tag that improves site performance

Example

[%cache id:'uniqueid' type:'content'%]
    <p>[@sku@]</p>
[%/cache%]

Usage

Creating a cache tag around a block of content saves everything contained in that block to Maropost Commerce Cloud, meaning that dynamic tags or logic held within only need to be rendered once, before that result is then shown to every other use who calls that same block.

This block will then only be refreshed to reflect updates if either the cache is cleared from within the control panel or if the type is configured correctly, whenever the data tags within are updated in Maropost Commerce Cloud.

Things to consider while implementing the cache tag

  • The maximum size of each cached snippet is 1MB (not including images and other assets)
  • Cached content should not include dynamic data such as customer details or cart details
  • Cached elements are updated hourly or whenever you refresh your cache
  • The type:'' parameter is required and must have a valid value (cannot be blank).

Caching inventory thumbnails

Caching thumbnails is one of the most cost effective caches you can apply within Maropost Commerce Cloud.

By using the [@inventory_id@] data tag for the cache tag we ensure that along side the appropriate type tag, each thumbnail has its own unique ID

In the sample below we cache a [%if%][%/if%] and store it to a thumbnail

[%cache type:'gallery' id:'[@inventory_id@]'%]
    [%if [@price@] > 100%]<p>Free shipping</p>[%/if%]
[%/cache%]

Caching menus

Caching CMS controlled menus

When using the menu tag to generate a menu that's statically defined via our CMS, you'll want to use the type:'menu' which will ensure that if you update the CMS menu, the system will automatically find & clear the cache for this tag.

Caching automatically generated content menus

When using either the content_menu or the now deprecated category_menu tags - you'll want to use the type:'cmenu' which will ensure that when any content in any content type is updated - the cache will be cleared to reflect the new category, blog, etc.

Note that if you are caching a menu that changes depending on the category you are on, for example, automatically being open when selected, you'll need a new ID for each state depending on the ID. The example below we use the [@config:current_category@] data tag to ensure a unique ID for each state of the menu.

[%cache type:'cmenu' id:'mainmenu-[@config:current_category@]'%]
    <p>[@name@]</p>
[%/cache%]

Parameters

Name Options Description
`id:''` String The ID of the cache, two cache tags with the same ID & type will conflict and only load the first result rendered. The same ID on two types of cache tags will act as individual cache tags
`type:''` `box`, `cmenu`, `display`, `gallery`, `list`, `menu` By using types, this will enable specific behaviour within Maropost Commerce Cloud to refresh a cache tag if the data tags within are changed in Maropost Commerce Cloud. See the **Type Options** table below for a description of the options
`ttl:''` Integer Optional. Defines how long to keep the content cached for, in seconds. By default, the content is cached for 3600 seconds (1 hour).

Type Options

Option Description
`box` Used to display products the customer has previously viewed. (e.g. **thumbs/product/box.template.html** template)
`cmenu` Used for category menus. Options can be changed by going to **Products** > **Product categories**
`display` Used to display details on product pages
`gallery` Used when displaying products in gallery or grid view (more than one product per row). (e.g. **thumbs/product/template.html** template)
`list` Used when displaying products in list view (one product per row). (e.g. **thumbs/product/list.template.html** template)
`menu` Used for menus. Menu options can be changed by going to **Webstore** > **Menus**

Was this article useful?

Be notified when this page is updated. Optional.