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

eZ Publish Cache In Details: Template-block Cache

Thursday 02 May 2013 8:56:14 am

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

How does cache view files are stored?

Storage of “template-blocks” is the complex and problematic part of the concept. Beyond the issue of volume of “template-blocks” mentioned in the previous sections (and dependant on the uniqueness of the usable keys), we are going to see that the correspondence between the cache files and their linked template blocks are not very intuitive...

« template-blocks » are stored in the directory:

{VarDir}/cache/template-block/
{VarDir} = value of the parameter VarDir in site.ini (or your own override), generally "var/mywebsite/"

 

At the root of this directory, 2 storage logic coexist:

  • The storage of template-blocks non-linked to a subtree_expiry
  • The storage of template-blocks linked to a subtree_expiry

 

 

Storage of template-blocks non-linked to a subtree_expiry

The files are divised into 4 hierarchy levels, based on the name of each of the files:

A file named “12345678.cache” will be stored in the following way:
{VarDir}/cache/template-block/1/2/3/12345678.cache

A file named “555666888.cache” will be stored the following way:
{VarDir}/cache/template-block/5/5/5/555666888.cache

The first 3 digits of the filename are exploited to create a tree as such:

  • {digit1}
     
     
     
    • {digit2}
       
       
       
      • {digit3}
         
         
         
        • {digit1}{digit2}{digit3}{other digits}.cache

 

 

 

Storage of template-blocks linked to a subtree

The logic is similar to that described above, adding an intermediate storage according to the root node_id defined in the subtree_expiry directive

A file named “12345678.cache”, with a subtree_expiry=2 will be stored the following way:
{VarDir}/cache/template-block/subtree/2/cache/1/2/3/12345678.cache

A file named “555666888.cache”, with a subtree_expiry=159 will be stored the following way:
{VarDir}/cache/template-block/subtree/1/5/9/cache/1/2/3/12345678.cache

The directory tree construction logic of the node_id is similar to the one with the first 3 digits of the filename, however the depth depends of the number of digits, which is not systematically higher than 3 as for the filenames.

 

 

Calculating the hash of the filename

As I mentioned previously, the filename does not really give details about the source of the matching cache-block (other than those stored based on a subtree_expiry). The hash is a CRC32 (and not MD5) of the parameters described in the table below

Table of the elements of the hash key (CRC32) of the template-blocks

Element of the hash key Meaning Example value
Position of the cache-block in the template + name of the template The cache-blocks with no unique identifiers, it is the combination between the name of the template and the location of the cache-block line which is used as an unicity key 78_1_78_94_extension/ezwebin/design/ezwebin/templates/pagelayout.tpl
78 = starting row1 = starting column78 = ending row94 = ending column
keys Key used in the directive keys=array(...) of the cache-block NULL
array( “/news”)
array( “/news”, “ezflow_site”)
site_access current site_access during the URL request ezflow_site
ezflow_site_admin

 

Expiry values of template-blocks caches are not part of the values used in the hash key. These values are evaluated at each execution and set in the compiled templates:

eZTemplateCacheBlock::retrieve( $cacheKeys, $subtreeExpiry, 7200, false );

  • $cacheKeys = The comination of the 3 values described in the table above
  • $subtreeExpiry = NULL OR node_id
  • 7200 = 2 hours by default, or the value fixed in expiry=...
  • false | true = value of the ignore_content_expiry

Note: As described in the table above, the position of the cache-block in the template impacts the hash key. The inference is that when you move a cache-block by just a single line or even a single character in the template, you cause:

  • The rebuilding of all the template-block caches linked to this cache-block
  • The doubling of storage files (because the previous template-block are not removed)

 

 
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