Title: Saving a Sharerich set invalidates every block on the
site
Problem/Motivation
SharerichForm::save() ends with:
// Clear block cache. Cache::invalidateTags(['block_view']);
block_view is the cache tag shared by every rendered block, so
saving one Sharerich set throws away the render cache for
every block on the site: menus, branding, page title, views
blocks, everything. On a large site that is a noticeable amount of work to
rebuild, caused by editing one button set.
The invalidation is there because SharerichBlock declares no
cache tags of its own. It renders the markup of a
sharerich config entity but never tells the render system that
its output depends on that entity, so without the blunt invalidation an edited
set would not show up.
Proposed resolution
Have the block declare what it actually depends on, and drop the site-wide
invalidation:
-
implement
getCacheTags()onSharerichBlock,
merging the parent tags with the cache tags of the
sharerichentity the block is configured to show; -
remove the
Cache::invalidateTags(['block_view'])call, since
saving the config entity then invalidates exactly the blocks that render it.
This is a performance fix, not a correctness one. Editing a set does currently
take effect; it just costs far more than it should.
Remaining tasks
- Add the cache tags and remove the invalidation.
-
Add a functional test that editing a set updates the rendered block, so the
removal of the blunt invalidation is proven safe. -
Check the block's cache contexts while there: it declares
url.path, which is what the token replacements need.
Comments
Comment #3
marcelovani