Skip to content

Commit 06eac08

Browse files
ericofksuess
authored andcommitted
Move plone.app.caching documentation to deployment/caching
1 parent 27eae04 commit 06eac08

File tree

15 files changed

+1007
-3
lines changed

15 files changed

+1007
-3
lines changed
165 KB
Loading
144 KB
Loading
137 KB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Composite views
2+
3+
A `composite view` is just a general term for most page views you see when you visit a Plone site.
4+
5+
It includes all content item views, content folder views, and many template views.
6+
7+
For our purposes, the distinguishing characteristic of composite views is the difficulty inherent in keeping track of all changes that might affect the final composited view.
8+
9+
Because of the difficulty of dependency tracking, composite views are often notoriously difficult to purge reliably from caching proxies so the default caching profiles set headers which expire the cache immediately (i.e. *weak caching*).
10+
11+
However, most of the inline resources linked to from the composite view (css, javascript, images, etc.) can be cached very well in proxy so the overall speed of most composite views will always be better with a caching proxy in front despite the page itself not being cached.
12+
13+
For relatively stable composite views or for those views for which you can tolerate some potential staleness, you might be tempted to try switching from *weak caching* to *moderate caching* with the `s-maxage` expiration value set to some tolerable value but first make sure you understand the issues regarding "split view" caching (see below).
14+
15+
A way to speedup a site with lots of composite view is to use "Terse" caching.
16+
17+
It caches a page for just a small time (be default 10s in browser and 60s in the caching proxy).
18+
19+
Thus the content is almost up to date, but on high load visitors are getting pages served from the cache.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
myst:
3+
html_meta:
4+
"description": "Control panel for Plone caching"
5+
"property=og:description": "Control panel for Plone caching"
6+
"property=og:title": "Caching Control Panel"
7+
"keywords": "Plone, deployment, automation, caching"
8+
---
9+
10+
(caching-control-panel-label)=
11+
12+
# Control panel
13+
14+
The Caching control panel in Plone's `Site Setup` supports a granular control of caching operations for a Plone site.
15+
16+
```{image} /_static/caching/ControlPanel-02.png
17+
:alt: Plone Control Panel (Classic UI)
18+
```
19+
20+
This control panel consists of four main tabs:
21+
22+
## `Change settings`
23+
24+
Where you can control caching behaviour, it contains four fieldsets:
25+
26+
### `Global settings`
27+
28+
For global options such as turning caching on or off.
29+
30+
### `Caching proxies`
31+
32+
Where you can control Plone's use of a caching proxy such or Varnish or a CDN.
33+
34+
### `In-memory caache`
35+
36+
Where you can control Plone's use of in-memory cache.
37+
38+
### `Caching operation`
39+
40+
Where caching rulesets (hints about views and resources used for caching purposes) can be associated with caching operations.
41+
42+
Those either intercept a request to return a cached response, or modifies a response to add cache control headers.
43+
44+
This is also where rulesets for legacy page templates (created through the web or the portal_skins tool) are configured.
45+
46+
### `Detailed settings`
47+
48+
Where you can configure parameters for individual caching operations.
49+
50+
51+
## `Import settings`
52+
53+
Where you can import pre-defined profiles of cache settings
54+
55+
## `Purge caching proxy`
56+
57+
Where you can manually purge content from a caching proxy.
58+
59+
This tab only appears if you have purging enabled under *Change settings*.
60+
61+
## `RAM cache`
62+
63+
Where you can view statistics about and purge the RAM cache.

docs/deployment/caching/enable.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
myst:
3+
html_meta:
4+
"description": "Caching Plone: Enable cache support"
5+
"property=og:description": "Enabling caching support for Plone"
6+
"property=og:title": "Caching Plone: Enabling support"
7+
"keywords": "Plone, deployment, automation, caching"
8+
---
9+
10+
(caching-installation-label)=
11+
12+
# Installation
13+
14+
Caching support is implemented by the package `plone.app.caching`, which is already shipped as a dependency of the *Plone* package, and it should be available on all Plone installations.
15+
16+
Even though Caching support is available in Plone, it is **not enabled by default**, although it is highly recommended to configure caching for every new Plone site in production.
17+
18+
## Enable Caching
19+
20+
Under the Advanced header, look for the `Caching` control panel -- currently only supported on the Classic UI -- and select it.
21+
22+
```{image} /_static/caching/ControlPanel-01.png
23+
:alt: Plone Control Panel (Classic UI)
24+
```
25+
26+
In the Caching control panel, the tab `Change settings` is selected and inside of it the tab `Global settings` have the option to **Enable caching** (disable by default)
27+
28+
```{image} /_static/caching/ControlPanel-02.png
29+
:alt: Caching Control Panel with caching disabled
30+
```
31+
32+
To enable caching, just click the checkbox:
33+
34+
```{image} /_static/caching/ControlPanel-03.png
35+
:alt: Caching Control Panel with caching enabled
36+
```
37+
38+
## Troubleshooting
39+
40+
When the Caching control panel is not there, there can be various reasons for this:
41+
42+
- If your installation does not load the `Plone` package, but only `Products.CMFPlone`, then `plone.app.caching` is not included.
43+
- If the package *is* included, but you add a Plone Site using the advanced form and disable caching, then the control panel is not there.
44+
45+
If you want to install it in an existing Plone Site:
46+
47+
1. Make sure the package is available in the Plone instance, by adding `plone.app.caching` or `Plone` to your installation.
48+
2. From the Plone Site Setup go to the ZMI (Zope Management Interface).
49+
3. Go to ``portal_setup``, and then to the Import tab.
50+
4. Select the HTTP caching support profile, perhaps easiest by id: `profile-plone.app.caching:default`.
51+
5. Click 'Import all steps'.

docs/deployment/caching/etags.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
myst:
3+
html_meta:
4+
"description": "ETags support for Plone caching"
5+
"property=og:description": "ETags support for Plone caching"
6+
"property=og:title": "ETags support for Plone"
7+
"keywords": "Plone, deployment, automation, caching"
8+
---
9+
10+
(caching-etags-label)=
11+
12+
# ETags
13+
14+
ETags are used in to check whether pages need to be re-calculated or can be served from cache.
15+
An ETag is simply a string. Under `plone.app.caching`, it is a string of tokens separated by pipe characters.
16+
The tokens hold values such as a user id, the current skin name, or a counter indicating how many objects have been added to the site.
17+
The idea is that the browser sends a request with the ETag included in an `If-None-Match` header.
18+
Plone can then quickly calculate the current ETag for the requested resource.
19+
If the ETag is the same, Plone can reply with `304 NOT MODIFIED` response, telling the browser to use its cached copy.
20+
Otherwise, Plone renders the page and returns it as normal.
21+
22+
Many caching operations use ETags. The tokens to include are typically listed in an `etags` tuple in the operation's options.
23+
24+
## Default tokens
25+
26+
The ETag names tokens supported by default are:
27+
28+
| etag | description |
29+
| --- | --- |
30+
| userid | The current user's id .|
31+
| roles | A list of the current user's roles in the given context. |
32+
| language | The language(s) accepted by the browser, in the `ACCEPT_LANGUAGE` header. |
33+
| userLanguage | The current user's preferred language. |
34+
| lastModified | A timestamp indicating the last-modified date of the given context. |
35+
| catalogCounter | A counter that is incremented each time the catalog is updated. I.e. each time content in the site is changed. |
36+
| locked | Whether or not the given context is locked for editing. |
37+
| skin | The name of the current skin (theme). |
38+
| resourceRegistries | A timestamp indicating the last-modified timestamp for the Resource Registries. This is useful for avoiding requests for expired resources from cached pages. |
39+
40+
## Additional tokens
41+
42+
It is possible to provide additional tokens by registering an `IETagValue` adapter.
43+
44+
This should be a named adapter on the published object (typically a view, file resource or Zope page template object) and request, with a unique name.
45+
46+
The name is used to look up the component. Thus, you can also override one of the tokens above for a particular type of context or request (e.g. via a browser layer), by registering a more specific adapter with the same name.
47+
48+
As an example, here is the `language` adapter:
49+
50+
```python
51+
from plone.app.caching.interfaces import IETagValue
52+
from zope.component import adapter
53+
from zope.interface import implementer
54+
from zope.interface import Interface
55+
56+
@implementer(IETagValue)
57+
@adapter(Interface, Interface)
58+
class Language:
59+
"""The `language` etag component, returning the value of the
60+
HTTP_ACCEPT_LANGUAGE request key.
61+
"""
62+
63+
def __init__(self, published, request):
64+
self.published = published
65+
self.request = request
66+
67+
def __call__(self):
68+
return self.request.get('HTTP_ACCEPT_LANGUAGE', '')
69+
```
70+
71+
This is registered in `ZCML` like so:
72+
73+
```xml
74+
<adapter factory=".etags.Language" name="language" />
75+
```

docs/deployment/caching/index.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
myst:
3+
html_meta:
4+
"description": "Caching Plone"
5+
"property=og:description": "Caching Plone"
6+
"property=og:title": "Caching Plone"
7+
"keywords": "Plone, deployment, automation, caching"
8+
---
9+
10+
(caching-label)=
11+
12+
# Caching
13+
14+
## Overview
15+
16+
HTTP caching is a technique used to speed up the delivery of web content by storing previously requested resources (such as images, scripts, and stylesheets) in a cache. When a user requests a resource, the cache can serve the resource directly from its storage, rather than having to fetch it from the original source.
17+
18+
It is possible to use a web accelerator, like {term}`Varnish` or {term}`Squid`, to implement HTTP caching in your own premises. The usual setup will have the web accelerator installed between Plone and the Internet, and when a request is made to the site the web accelerator will intercept the request and check to see if it has a cached copy of the requested resource. If a cached copy is found, the accelerator will serve the cached copy directly to the client, otherwise it will make a request to the backend Plone server and then store a copy on the content in its local cache.
19+
20+
A Content Delivery Network (CDN) can also be used to implement the HTTP caching and speed up the delivery of web content. A CDN is a network of servers located in multiple geographic regions that work together to deliver web content to users more quickly and efficiently. When a user requests a resource from a website that is using a CDN, the request is routed to the nearest server in the CDN, rather than having to travel all the way to the website's origin server.
21+
22+
## Plone support
23+
24+
Plone, since version 4.1, ships with a powerful and extensible `HTTP` and `In-Memory` cache support, implemented by the package `plone.app.caching`.
25+
26+
27+
```{toctree}
28+
:maxdepth: 2
29+
:hidden: true
30+
31+
enable
32+
control-panel
33+
profiles
34+
rulesets-and-caching-operations
35+
proxies
36+
ram-cache
37+
etags
38+
composite-views
39+
split-views
40+
restapi
41+
```
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)