|
| 1 | +--- |
| 2 | +myst: |
| 3 | + html_meta: |
| 4 | + "description": "Caching profiles for Plone" |
| 5 | + "property=og:description": "Caching profiles for Plone" |
| 6 | + "property=og:title": "Caching profiles for Plone" |
| 7 | + "keywords": "Plone, deployment, automation, caching" |
| 8 | +--- |
| 9 | + |
| 10 | +(caching-profiles-label)= |
| 11 | + |
| 12 | +# Caching profiles |
| 13 | + |
| 14 | +All persistent configuration for the caching machinery is stored in the configuration registry, as managed by `plone.app.registry`. |
| 15 | + |
| 16 | +This can be modified using the `registry.xml` GenericSetup import step. |
| 17 | + |
| 18 | +The *Import settings* tab of the control panel allows you to import these caching profiles. |
| 19 | + |
| 20 | + |
| 21 | +## Default caching profiles |
| 22 | + |
| 23 | +`plone.app.caching` includes three default caching profiles. |
| 24 | + |
| 25 | +Two of these profiles encapsulate the cache settings that are known to work well with a typical default Plone installation: |
| 26 | + |
| 27 | +### Without caching proxy |
| 28 | + |
| 29 | +Settings useful for setups without a caching proxy. |
| 30 | + |
| 31 | +### With caching proxy |
| 32 | + |
| 33 | +Settings useful for setups with a caching proxy such as Squid or Varnish. |
| 34 | +The only difference from the "without caching proxy" profile are some settings to enable proxy caching of files/images in content space and content feeds. |
| 35 | + |
| 36 | +## Custom caching profiles |
| 37 | + |
| 38 | +Caching policies are often a compromise between speed and freshness. |
| 39 | +More aggressive caching often comes at the cost of increased risk of stale responses. |
| 40 | +The default profiles provided tend to err on the side of freshness over speed so there is some room for tweaking if greater speed is desired. |
| 41 | + |
| 42 | +Customization may also be needed if third-party products are installed which require special treatment. |
| 43 | +Examine the HTTP response headers to determine whether the third-party product requires special treatment. |
| 44 | +Most simple cases probably can be solved by adding the content type or template to the appropriate mapping. |
| 45 | +More complicated cases, may require custom caching operations. |
| 46 | + |
| 47 | +A GenericSetup profile used for caching should be registered for the `ICacheProfiles` marker interface to distinguish it from more general profiles used to install a product. |
| 48 | +This also hides the profile from Plone's Add-ons control panel. |
| 49 | + |
| 50 | +Here is an example from this package: |
| 51 | + |
| 52 | +```xml |
| 53 | + <genericsetup:registerProfile |
| 54 | + name="with-caching-proxy" |
| 55 | + title="With caching proxy" |
| 56 | + description="Settings useful for setups with a caching proxy such as Squid or Varnish" |
| 57 | + directory="profiles/with-caching-proxy" |
| 58 | + provides="Products.GenericSetup.interfaces.EXTENSION" |
| 59 | + for="plone.app.caching.interfaces.ICacheProfiles" |
| 60 | + /> |
| 61 | +``` |
| 62 | + |
| 63 | +The directory `profiles/with-caching-proxy` contains a single import step, `registry.xml`, |
| 64 | +containing settings to configure the ruleset to operation mapping, |
| 65 | +and setting options for various operations. |
| 66 | + |
| 67 | +At the time of writing, this includes: |
| 68 | + |
| 69 | +```xml |
| 70 | + <record name="plone.caching.interfaces.ICacheSettings.operationMapping"> |
| 71 | + <value purge="False"> |
| 72 | + <element key="plone.resource">plone.app.caching.strongCaching</element> |
| 73 | + <element key="plone.stableResource">plone.app.caching.strongCaching</element> |
| 74 | + <element key="plone.content.itemView">plone.app.caching.weakCaching</element> |
| 75 | + <element key="plone.content.feed">plone.app.caching.moderateCaching</element> |
| 76 | + <element key="plone.content.folderView">plone.app.caching.weakCaching</element> |
| 77 | + <element key="plone.content.file">plone.app.caching.moderateCaching</element> |
| 78 | + <element key="plone.content.dynamic">plone.app.caching.terseCaching</element> |
| 79 | + </value> |
| 80 | + </record> |
| 81 | +``` |
| 82 | + |
| 83 | +Default options for the various standard operations are found in the `registry.xml` file that is part of the standard installation profile for this product, in the directory `profiles/default`. |
| 84 | + |
| 85 | +The custom profile overrides a number of operation settings for specific rulesets (see below). |
| 86 | + |
| 87 | +For example: |
| 88 | + |
| 89 | +```xml |
| 90 | + <record name="plone.app.caching.weakCaching.plone.content.itemView.ramCache"> |
| 91 | + <field ref="plone.app.caching.weakCaching.ramCache" /> |
| 92 | + <value>True</value> |
| 93 | + </record> |
| 94 | +``` |
| 95 | + |
| 96 | +This enables RAM caching for the "weak caching" operation for resources using the ruleset `plone.content.itemView`. |
| 97 | +The default is defined in the main `registry.xml` as:: |
| 98 | + |
| 99 | +```xml |
| 100 | + <record name="plone.app.caching.weakCaching.ramCache"> |
| 101 | + <field type="plone.registry.field.Bool"> |
| 102 | + <title>RAM cache</title> |
| 103 | + <description>Turn on caching in Zope memory</description> |
| 104 | + <required>False</required> |
| 105 | + </field> |
| 106 | + <value>False</value> |
| 107 | + </record> |
| 108 | +``` |
| 109 | + |
| 110 | +Notice how we use a *field reference* to avoid having to re-define the field. |
| 111 | + |
| 112 | +It may be useful looking at these bundled `registry.xml` for inspiration if you are building your own caching profile. |
| 113 | +Alternatively, you can export the registry from the `portal_setup` tool and pull out the records under the prefixes `plone.caching` and `plone.app.caching`. |
| 114 | + |
| 115 | +Typically, `registry.xml` is all that is required, but you are free to add additional import steps if required. |
| 116 | +You can also add a `metadata.xml` and use the GenericSetup dependency mechanism to install other profiles on the fly. |
0 commit comments