Skip to the content
Documentation

Smart view cache cleaning

No ratings yet

Publishing an object clears the view cache of its locations, their parents, objects with the same keywords and related objects (see Clearing the view cache). That is not always enough: a folder that lists the newest articles of all its subfolders, or a front page with the latest forum topics, shows stale content after an article deep below it is published. The smart view cache cleaning adds rules per class: when an object of class X is published, also clear these other nodes.

Switching it on

Set it in viewcache.ini of the siteaccess where content is published (usually the administration), or in settings/override:

# settings/siteaccess/<admin siteaccess>/viewcache.ini.append.php
[ViewCacheSettings]
# disabled (shipped) | enabled | exclusive
SmartCacheClear=enabled
Value Effect
disabled Only the default clearing
enabled The rules of a class are applied in addition to the default clearing
exclusive For a class with rules, only its rules are applied, instead of the default clearing

The rules

A rule is a group named after the class identifier of the published object. The kernel walks up the path of each location of the object (path_string) and checks the parents:

Setting Meaning
DependentClassIdentifier[] Class identifiers (not IDs). A parent of one of these classes is added to the nodes to clear.
ClearCacheMethod[] What to clear for each added node: object (all its locations), parent (its parents), relating (its related objects, as ClearRelationTypes[] says), keyword (objects with the same keywords), siblings, children (its direct children), all (all of these) or none.
MaxParents How many parents of the path are checked; without it, all of them.
ObjectFilter[] Object IDs. When given, only parents whose object has one of these IDs are added.
AdditionalObjectIDs[] Object IDs whose locations are always cleared too, wherever they are in the tree.
ClearCacheBlocks disabled: publishing objects of this class does not clear the template-block caches ({cache-block} without ignore_content_expiry).

Examples

The tree: Company (folder, node 77) > About (folder, 78) > News (folder, 80) > article2 (82). Without rules, publishing article2 clears article2 and News.

Every folder above an article:

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

Publishing article2 now clears article2, News, About and Company (and every folder further up).

Only the nearest two: add MaxParents=2, and only News and About are added.

Only one particular folder: with the Company folder's object ID 74, add

ObjectFilter[]
ObjectFilter[]=74

Publishing article2 then clears article2, News (the default clearing) and Company.

Pages elsewhere in the tree: a front page (object 64) and a product (object 69) that show the latest articles:

[article]
AdditionalObjectIDs[]
AdditionalObjectIDs[]=64
AdditionalObjectIDs[]=69

A forum listing, from the comments of the shipped settings/viewcache.ini:

[forum_topic]
DependentClassIdentifier[]
DependentClassIdentifier[]=forum
ClearCacheMethod[]
ClearCacheMethod[]=object
ClearCacheMethod[]=relating

Good to know

  • The rules only add nodes. Clearing too much has a cost: when more than site.ini [ContentSettings] CacheThreshold nodes (250) are to be cleared, all view caches are expired at once.
  • Pages that list content from all over the site are often better cached with a {cache-block} with subtree_expiry or expiry than cleared by rules.
  • Clear the INI caches after changing viewcache.ini.

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.