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() on SharerichBlock,
    merging the parent tags with the cache tags of the
    sharerich entity 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

marcelovani created an issue. See original summary.

  • marcelovani committed 0120c0f7 on 8.x-1.x
    Issue #3619611: Declare the set's cache tags on the block
    
    The set form...
marcelovani’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.