Skip to content

Commit 4dbb953

Browse files
authored
Rewrite tag based cache invalidation chapter (contao#638)
* rewrite tag based cache invalidation chapter * update caching chapter according to ausis suggestions * fix tag invalidation chapter after review by @Toflar * fix typos
1 parent 236adda commit 4dbb953

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

docs/dev/framework/caching.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,47 @@ event.
227227
#### Cache tag invalidation within the Contao back end
228228

229229
When working with DCAs in the Contao back end you don't have to register callbacks at various places to make sure certain
230-
tags are being invalidated. This is because Contao invalidates a certain set of tags whenever a back end entry is created,
231-
updated or deleted. The tags are as follows:
230+
tags are being invalidated. This is because Contao invalidates a certain set of tags whenever a back end entry is created,
231+
updated or deleted.
232232

233-
* `contao.db.<table-name>`
234-
* `contao.db.<table-name>.<id>`
235-
* `contao.db.<parent-table-name>` (only if there is a parent table defined)
236-
* `contao.db.<parent-table-name>.<pid>` (only if there is a parent record)
233+
The tags are as follows:
234+
235+
* `contao.db.<table-name>.<id>` (The record itself)
236+
* `contao.db.<table-name>` (Only if the DCA has no parent table defined)
237+
238+
If the DCA has a **parent table**, Contao recursively iterates upwards the table hierarchy and invalidates the following
239+
tags as well:
240+
241+
* `contao.db.<parent-table-name>` (Only for the topmost parent table)
242+
* `contao.db.<parent-table-name>.<pid>`
243+
244+
If the DCA has one or many **child tables**, Contao recursively iterates downwards the table hierachy and invalidates the
245+
following tags as well:
246+
247+
* `contao.db.<child-table-name>.<cid>`
248+
249+
##### Example: Edit a news article
250+
251+
Imagine you have edited a news article with ID 42. Contao will now automatically send an invalidation request to the
252+
reverse proxy to invalidate all responses associated with the following tags:
253+
254+
* `contao.db.tl_news_archive` (The topmost parent table)
255+
* `contao.db.tl_news_archive.1` (The parent record)
256+
* `contao.db.tl_news.42` (The record itself)
257+
* `contao.db.tl_content.420` (The first child record)
258+
* `contao.db.tl_content.421` (The second child record)
259+
260+
Only the topmost parent table tag will be invalidated, i.e. `contao.db.tl_news_archive`, but not `contao.db.tl_news`
261+
or `contao.db.tl_content`.
262+
263+
##### Example: Edit a contact record (custom DCA)
264+
265+
Imagine now you have your own DCA table `tl_contact_details` with no parent or child tables. When you edit the contact
266+
record with ID 42, Contao will automatically invalidate the following tags:
267+
268+
* `contao.db.tl_contact_details.42` (the contact record itself)
269+
* `contao.db.tl_contact_details` (the table itself)
237270

238-
So let's say you had a DCA table named `tl_news`. When you edit ID `42`, Contao would automatically send an invalidation
239-
request to the reverse proxy to invalidate all responses associated with the tags `contao.db.tl_news` and `contao.db.tl_news.42`.
240271
If you follow this convention and tag your responses accordingly in the front end, you don't have to do any work in the
241272
back end at all!
242273

0 commit comments

Comments
 (0)