This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Learn » eZ Publish » eZ Publish Cache In Details: Template...

eZ Publish Cache In Details: Template Compilation And INI Cache

Tuesday 15 January 2013 1:02:43 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Working in ShareCompiledTemplates mode

When activating the ShareCompiledTemplates=enabled parameter (“TemplateSettings” section in site.ini), the hash key of the compiled templates storage is much more trivial, namely the path of the template and language of the current siteaccess:

 

Table of the elements of the hash key, in ShareCompiledTemplates=enabled mode

Element of the hash key Meaning Example of value
key MD5 of the full path of the template md5(‘extension/ezwebin/design/ezwebin/templates/pagelayout.tpl’)
language Language defined for the siteaccess used at the moment of compiplation fre-FR

This configuration is perfectly suited to eZ Publish instances powering many siteaccess, such as website factories, which we do not control the number of siteaccess as time goes.
However, we must be attentive to setting values (.ini files) specific to each siteaccess, those values are compiled in the templates by default. It is therefore necessary to dynamically load these setting values for each execution of the templates, by using either:

  • the global directive DynamicTemplateMode=enabled (site.ini [eZINISettings])
  • or, on a case by case basis, ‘dynamic’parameter with the eZINI template operator
 

How to force recompilation of a set of specific templates?

To force the recompilation of one or many specific template(s) (in this example, 2 templates of ezwebin):

<em>php bin/php/eztc.php -s monsiteaccess --force extension/ezwebin/design/ezwebin/templates/pagelayout.tpl extension/ezwebin/design/ezwebin/templates/page_leftmenu.tpl</em>

Result:

Compiled template file: extension/ezwebin/design/ezwebin/templates/pagelayout.tpl
Compiled template file: extension/ezwebin/design/ezwebin/templates/page_leftmenu.tpl

 

When the list of templates is a bit long, we can simplify things by using a list stored in a txt file or using the result of a ls / find command:
Compiles all the templates of ezwebin that start with “page_header_”:

find extension/ezwebin/ -name "page_header_*.tpl" | xargs php bin/php/eztc.php –force

Compiles all templates figuring in the template_list.txt file:

cat template_list.txt | xargs php bin/php/eztc.php –force

Warning : The previous chapter told us that the hash key of a compiled template uses the $pageLayoutVariable parameter. eZ Publish does deduct this value only when it is called in an URL of the “layout/set/...” type, on the fly in index.php. The eztc.php script can not know and plan in advance the various possible combinations.
In other words, when using the layout module:

  • eZ Publish compiles as many version of the templates as the different used layout, for example a template “page_head.tpl” will exist in 4 versions if 3 additional layouts are used (default version and 3 specific versions)
  • The eztc.php script does not recompile the default layout, the 3 other compilations will be made by front requests of the involved URLs. To update these specific templates without purging the entire cache, we will need to remove individual versions of these templates in the {VarDir}/cache/template/compiled/ directory, then wait for them to be requested by website visitors (generally, the impact is negligible in performance when the operation is focused on a single templates set)

 

To manually remove the different variants of a compiled template in order to force the recompilation on the fly (for example for the page_head.tpl):

find var/ezflow_site/cache/template -name "page_head-*" | xargs rm
 

How to expire the template overrides cache?

When you add templates to your specific extension and you set overrides for these templates, two caches are involved in this operation:

  • The cache of the list of design directories by siteaccess gradualy invoked, stored in {VarDir}/cache/designbase_{hash}.php. The {hash} consists of a MD5 of the invoked site_access.

It is possible to expire this cache by the command:

php bin/php/ezcache.php -s monsiteaccess --clear-id=design_base
  • The cache of the templates overrides list by site_access gradualy invoked, stored in {VarDir}/cache/override/override_{hash}.php. The {hash} consists of a MD5 of : 
    • the array of /design directories (design.ini [ExtensionSettings] DesignExtensions[])
    • the “standard” SiteDesign
    • the SiteDesign declared in site.ini [DesignSettings] SiteDesign.

It is possible to expire this cache by the command:

php bin/php/ezcache.php -s monsiteaccess --clear-id=template-override
 
36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)

Proudly Developed with from