The code executed on each block render (thus on each page load) does impact the site performance negatively.
If we cache the block based on the path, we improve the performance immensely.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Test_article_new_title_My_beautiful_website (1).jpg | 56.29 KB | lolandese |
| #4 | Test_article_new_title_My_beautiful_website.jpg | 51.71 KB | lolandese |
| #4 | Test_article_old_title_My_beautiful_website.jpg | 48.06 KB | lolandese |
| #3 | permalink_block-cache_per_path-3133256-3.patch | 749 bytes | lolandese |
Comments
Comment #2
lolandese commentedAn example, 8 - How do I correctly setup caching for my custom block showing content depending on the current node? - Drupal Answers.
Comment #3
lolandese commentedAppears to be as simple as defining a cache context in the render array. See Cache contexts | Drupal 8 guide on Drupal.org.
Comment #4
lolandese commentedPatch applies cleanly
Module enables successfully
Module uninstalls successfully
PHPUnit tests pass
See above.
8.x-1.x: PHP 7.3 & MySQL 5.7, D8.8.5 2 pass
Test if the site still works, the Permalink block can be placed and works.
Manual functional testing
We change the title with 'Generate automatic URL alias' being unselected. That means the path (alias) stays unaltered. This should show the permalink block with the old title being used, thus showing the cached version of the block.
We now change the title again but this time with 'Generate automatic URL alias' being selected. That means the path (alias) alters. This should show the permalink block with the new title being used, thus showing the refreshed version of the block.
We did the same with the translated version of the node, just to be sure, and confirm the same expected behavior.
Comment #6
lolandese commented