ibexa

Path

ez publish / technical manual / 3.8 / features / view caching / smart view cache cleaning


Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

Smart view cache cleaning

The smart viewcache cleaning system (referred to as "svcs" on this page) makes it possible to set up custom rules that control which nodes the view cache should be cleared for when a published object is changed. This feature is turned off by default and thus the system will only clear the view cache for the following nodes when a new version of an object is published:

  • All published nodes of this object
  • The parent node(s)
  • Nodes of the related and reverse related objects that have relations at the object level (this is controlled by the "ClearRelationTypes" configuration setting)
  • Nodes of the objects that have the same keyword (if the object contains attribute(s) of the "Keywords" datatype)

If you want to use the smart viewcache cleaning feature, make sure the "viewcache.ini.append.php" file located in the "settings/siteaccess/example_admin" directory (replace "example_admin" by the name of the siteaccess that is used for adding and editing content) contains the following lines:

[ViewCacheSettings]
SmartCacheClear=enabled

These lines will instruct the system to follow the rules specified in this configuration file in addition to the default behavior. The configuration file usually includes a single, common settings section called "[ViewCacheSettings]" and multiple specific sections that describe the rules determining which additional nodes the view cache should be cleared for. These sections are named after the class identifiers.
When a published object is changed, svcs gets its identifier as an input parameter. It checks which class this object belongs to and looks for a section named after that class identifier in the "viewcache.ini" configuration file (and its overrides). The rules specified in this section will be applied to the parent nodes that are listed in the path_string attribute of the initially changed node. If the published object has several nodes/locations, svcs will sequentially handle their path strings. The following list reveals how svcs will handle each node of the published object:

  1. Scan the parent nodes listed in the node's "path_string" attribute (the maximal quantity of nodes that will be scanned is controlled by the "MaxParents" setting).
  2. Perform the following actions for each of the parent nodes:
    • Check which class the object encapsulated by that node belongs to.
    • If the identifier of that class is listed in the "DependentClassIdentifier[]" array, add the matching parent node to the list of additional nodes.
  3. If the "ObjectFilter[]" setting is empty, clear the view caches for additional nodes. Otherwise, check the identifiers of the objects encapsulated by additional nodes and only clear caches for those that have their object identifiers listed in the "ObjectFilter[]" array. In both cases, the caches are cleared using the method(s) specified in the "ClearCacheMethod[]" setting.

The following table gives detailed description for the configuration settings mentioned above.

Name

Type

Description

DependentClassIdentifier

An array of class identifiers (not ID numbers)

Specifies which content classes that will be considered as "dependent classes". If a node encapsulating an object of such a class is listed in "path_string", svcs will add it to the list of additional nodes. The view cache for additional nodes will be cleared using the method(s) specified in the next setting.

ClearCacheMethod

An array of strings

Sets which method(s) to use when clearing the view caches for additional nodes. This setting is an array of strings where only six pre-defined values can be used (see the next table).

Name

Description

object

Clear the view cache for all the locations (nodes) of the object.

parent

Clear the view cache for the parent node(s) of the object.

relating

Clear the view cache for the related and reverse related objects that have relations at the object level (according to the relation types specified using the "ClearRelationTypes" configuration setting).

keyword

Clear the view cache for the objects that have the same keyword as this object.

siblings

Clear the view cache for all the siblings of this node/object.

all

Clear the view cache for all the listed above.

ObjectFilter

An array of object ID numbers

If specified, the view caches will only be cleared for those additional nodes that encapsulate the objects with these identifiers. If not specified, all additional nodes will have their view cache cleared.

MaxParents

Integer

Sets how many parents in "path_string" will be checked . If not specified, svcs will scan all the parents listed in "path_string".

Example 1

Let's say that both view caching and svcs are enabled with the following part of a content structure:

a part of the site content structure

A part of the site content structure.


If you do not specify any rules for svcs, changing an article will lead to clearing the view caches for all its published nodes, parent node(s), nodes of the related and reverse related objects, nodes of the objects having the same keyword (this is the default behavior of svcs).

If the "article2" object has only one location, does not contain any keywords and is not related to any other objects, changing it will lead to clearing the view cache of the article itself and the "News" folder. The view cache of the "About" and "Company" nodes will not be cleared.

However, you can extend this default behavior by adding the following configuration group to the "viewcache.ini.append.php" configuration file of your (admin) siteaccess:

[article]
DependentClassIdentifier[]
DependentClassIdentifier[]=folder
ClearCacheMethod[]
ClearCacheMethod[]=object

Now, if an article is changed, the system will fetch all the parent nodes of this article sequentially according to its "path_string" attribute (the path string for "article2" ends with "/77/78/80/82/"), check which of them are folder nodes and clear the view cache for those folders. This means that changing "article2" will lead to clearing the view cache of "article2", "News", "About", "Company" and all the parent folder nodes that are located above the "Company" node.

Example 2

It is possible to limit the depth of fetching node IDs from the "path_string" attribute like this:

[article]
DependentClassIdentifier[]
DependentClassIdentifier[]=folder
ClearCacheMethod[]
ClearCacheMethod[]=object
MaxParents=2

This will tell the system to take into account only two penultimate items from the node's path string (i.e. parent and grandparent of the node). This means that changing "article2" will only lead to clearing the view caches of "article2", "News" and "About". The view cache of the "Company" node and its parent folders will not be cleared.

Example 3

You can use the "ObjectFilter[]" configuration array so that a folder node listed in "path_string" will not be included in the list of additional nodes unless the object encapsulated by this node is explicitly specified in the following way:

ObjectFilter[]
ObjectFilter[]=<object_id1>
ObjectFilter[]=<object_id2>
...

Assuming that the "Company" folder object in example 1 has ID number 74 (while its node ID is 77), you can specify the following settings in the "viewcache.ini.append.php" of your (admin) siteaccess:

[article]
DependentClassIdentifier[]
DependentClassIdentifier[]=folder
ClearCacheMethod[]
ClearCacheMethod[]=object
ObjectFilter[]
ObjectFilter[]=74

If "article2" is changed, svcs will check which of the folder nodes listed in the given path string (nodes 80, 78, 77, ...) have their object ID numbers matching one of the values in the "ObjectFilter[]" array and thus only the "Company" page will be included in the list of additional nodes. The system will only clear view caches of "article2", "News" and "Company" (according to the default behavior and the given svcs rules). The view cache of the "About" page will not be cleared because the ID number of that object is not 74.

Svitlana Shatokhina (23/10/2006 9:59 am)

Svitlana Shatokhina (10/04/2007 3:29 pm)

Svitlana Shatokhina, Balazs Halasy


Comments

  • Syntax has changed after 3.7

    The concepts are identical, but the variables names are not the same on the 3.7 version.

    Read the settings/viewcache.ini the exemples are with the proper syntax.
  • Parents, related, siblings and keywords ok, but what about other nodes ?

    Do I miss something, or when publishing a given object you can NOT clear the view cache for arbitrary nodes (meaning not related, parents, siblings or with the same keyword) ?

    See example 1 above in this page : when publishing an article in news folder, is there a way to clear the partner folder cache ?
    • Re: Parents, related, siblings and keywords ok, but what about other nodes ?

      From 3.9, it is possible to clear the caches for a set of arbitrary objects when objects of specific types are changed. There is a new setting called "AdditionalObjectIDs[]". If it contains a list of object identifiers, the system will clear the view cache for all the locations (nodes) of these objects.
      • Re: Re: Parents, related, siblings and keywords ok, but what about other nodes ?

        That's great, thanks a lot for your really useful reply !