Problem/Motivation
By inspecting a disproportionate cache_render
table I realized a block was being cached by url and that made no sense to me.
Further analysis showed me that this was happening for any single block. Finally found vlsuite_model was the responsible of that. It started declaring url cache context to every cache object. This regression was introduced in the solution to
🐛
Layout Builder modal dialog is broken with Drupal 10.1+
Fixed
.
I think cache contexts are only used in render arrays so, although it is added for any object in a config.factory.override
service, the impact of this is limited to cache render and not all cache objects.
In the practical side this means that for each url, a set of all cachable render arrays is stored. So cache size tends to N * number-of-urls, where N is the number of cacheable render elements.
Steps to reproduce
Enabling vlsuite_model is enough to reproduce this bad behaviour.
A way to test the evidence, is comparing the number of cache items generated with and without vlsuite_model enabled.
ddev drush site:install --account-name=admin --account-pass=admin -y
ddev composer require drupal/devel_generate drupal/vlsuite
ddev drush en -y devel_generate
ddev drush devel-generate:content
echo "## Without vlsuite_modal"
ddev drush cr
wget -q -r --spider https://testbed-drupal10.ddev.site/
ddev drush sql:query "select concat('Total items in cache render: ',count(cid)) from cache_render; select concat('Items with url cache context: ', count(cid)) from cache_render where cid like '%[url]%';"
echo "## With vlsuite_modal"
ddev drush en -y vlsuite
ddev drush en -y vlsuite_modal
ddev drush cr
wget -q -r --spider https://testbed-drupal10.ddev.site/
ddev drush sql:query "select concat('Total items in cache render: ',count(cid)) from cache_render; select concat('Items with url cache context: ', count(cid)) from cache_render where cid like '%[url]%';"
<code>
This is the output of above test:
<code>
## Without vlsuite_modal
Total items in cache render: 356
Items with url cache context: 4
## With vlsuite_modal
Total items in cache render: 902
Items with url cache context: 740
We can dig further:
$ ddev drush sql:query "select cid from cache_render where cid like '%url%'" --extra=-A | cut -d: -f -2 | sort | uniq -c | sort -h
1
4 view:taxonomy_term
5 view:frontpage
149 entity_view:node
614 entity_view:block
$ ddev drush sql:query "select cid from cache_render where cid like '%url%'" --extra=-A | cut -d: -f -3 | sort | uniq -c | sort -h | tail -n 20
5 view:frontpage:display
6 entity_view:node:1
7 entity_view:node:26
7 entity_view:node:34
7 entity_view:node:45
9 entity_view:node:36
9 entity_view:node:49
40 entity_view:block:olivero_help
40 entity_view:block:olivero_main_menu
40 entity_view:block:olivero_messages
40 entity_view:block:olivero_powered
40 entity_view:block:olivero_search_form_narrow
40 entity_view:block:olivero_search_form_wide
40 entity_view:block:olivero_site_branding
40 entity_view:block:olivero_syndicate
42 entity_view:block:olivero_breadcrumbs
46 entity_view:block:olivero_primary_local_tasks
46 entity_view:block:olivero_secondary_local_tasks
80 entity_view:block:olivero_account_menu
80 entity_view:block:olivero_primary_admin_actions
All those blocks should be cached only once.
Proposed resolution
Probably cache context is not needed here, since the cache additions don't vary by url. Anyway the compromise solution is to add only this cache context in layout builder pages.
Remaining tasks
MR
User interface changes
None
API changes
None
Data model changes
None