Share » Learn » eZ Publish » eZ Publish Performance Optimization...

eZ Publish Performance Optimization Part 3 of 3: Practical Cache and Template Solutions

Wednesday 24 January 2007 5:05:00 pm

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

The goal of smart viewcache cleaning is to provide flexibility when cleaning the viewcache of an object's nodes. It is aimed at extending the default behavior when cleaning the cache in specific situations.

viewcache.ini.append.php: 
[ViewCacheSettings] 
SmartCacheClear=disabled

SmartCacheClear should be used with a set of custom rules. Enabling SmartCacheClear can actually slow down the publishing process due to the need to apply the custom rules. Here are two practical examples to demonstrate why smart viewcache cleaning should be enabled and configured with additional rules.

Example 1 - Forum

Assume that we have a content structure like this:

eZ Publish(nodeID = 2, class_identifier = folder) | |-- Forum folder(nodeID = 58, 
class_identifier = folder)  |  |-- Interesting forum(nodeID = 59, 
class_identifier = forum)  |  |-- Topic 1(nodeID = 60, 
class_identifier = forum_topic)  | |  | |-- Reply1(nodeID = 62, 
class_identifier = forum_reply)  | |  | |-- Reply2(nodeID = 126, 
class_identifier = forum_reply)  | |  | | -- Reply3(nodeID = 127, 
class_identifier = forum_reply)  |  |-- Topic 2(nodeID = 61, 
class_identifier = forum_topic)

Users can add replies to Topic 1. By default, when SmartCacheClear is enabled and a user adds a new reply to Topic 1, the viewcache of this reply and its parent (Topic 1) is cleared.

Case 1

Assume now that the forum name and number of posts in this forum are displayed when viewing Forum folder. By default, after a new reply is added, the cache of Forum folder is not cleared and thus the number of posts will display outdated information. To fix this, you can use the "extended" behavior of the smart viewcache cleaning system. The appropriate rule is as follows: if a new forum_reply is added to forum, clear the cache of the parent of forum. In this case, the following lines should be added to the viewcache.ini.append.php file:

[forum_reply] 
DependentClassIdentifier[] 
DependentClassIdentifier[]=forum 
ClearCacheMethod=clear_parent_nodes_caches_only

For example, if you add the Reply3 object, the nodeID path is: /1/2/58/59/60/127. Then, the smart viewcache cleaning system will search for nodes where class_identifier is equal to one of the values in the DependentClassIdentifier variable. The search is conducted in reverse order: the node with nodeID=60 will be checked first, then the node with nodeID=59. The node with nodeID=60 doesn't belong to the forum class, so its cache remains untouched. The next node has nodeID=59 and belongs to the forum class, so its cache is cleared. The other nodes in the path (58,2) do not belong to the forum class, so their caches remain untouched.

Case 2

Assume now that in addition to Case 1 we have a folder named Common folder, published under the eZ Publish folder and containing Forum folder as a related object. Since the Forum folder cache is cleared when a new forum_reply is published, the cache of Common folder has to be cleared as well. For this purpose, we need to add another rule to viewcache.ini.append.php:

[forum] 
DependentClassIdentifier[] 
DependentClassIdentifier[]=folder 
ClearCacheMethod=clear_relating_caches_only 
MaxParents=1

Now when a new forum_reply object is created, the cache for Forum folder and Common folder need to be cleared. There are two folder nodes in the path: one with id=2 (eZ Publish) and one with id=58 (Forum folder). But we do not need to clear cache for the eZ Publish folder (nodeID=2). The MaxParents setting fixes this: folder objects that are more than one node away from the forum node are ignored. The two rules from Case 1 and Case 2 can be combined and replaced with the following rule:

[forum_reply] 
DependentClassIdentifier[] 
DependentClassIdentifier[]=folder 
ClearCacheMethod=clear_object_and_relating_objects_caches 
MaxParents=3; 
#If 'Forum folder' has object_id=56 for example then the rule above can 
be more hard by adding next lines: ObjectFilter[] ObjectFilter[]=56

The lines above restrict the rule to one folder object that has object_id=56.

Example 2 - Image gallery

Assume that we have a content structure like this:

eZ Publish(nodeID = 2, class_identifier = folder) | |-- Gallery(nodeID = 58, 
class_identifier = gallery)  |  |-- Image 1(nodeID = 59, 
class_identifier = image)  |-- Image 2(nodeID = 60, 
class_identifier = image)  |-- Image 3(nodeID = 61, 
class_identifier = image)

By default, when SmartCacheClear is enabled and a user adds a new image to Gallery, the viewcache of this image and its parent (Gallery) is cleared. In our example, assume that we need to display images stored under the Gallery subtree in the full view but also in each image view. In this case, when the new image is published we need to clear the viewcache of the parent (Gallery), the new uploaded image and its siblings. Without configuring smart viewcache rules, the other images (the siblings) are outdated. The appropriate rule is as follows: if a new image is added to Gallery, clear the cache of the parent of the Gallery but also of the siblings. In this case, the following lines should be added to the viewcache.ini.append.php file:

[image] 
DependentClassIdentifier[] 
DependentClassIdentifier[]=gallery 
ClearCacheMethod[] 
ClearCacheMethod[]=parent 
ClearCacheMethod[]=siblings 
MaxParents=1
36 542 Users on board!

Tutorial menu

Printable

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

Author(s)