Make block cacheable

Created on 18 April 2023, almost 2 years ago

Problem/Motivation

Since Add support for "Search API (tags based)" caching in Views Fixed , facets can be cached. So the facets_block block should also be cacheable (and inherit the facets cache parameters).

Steps to reproduce

Add a facets_block block to a page.
The block is recalculated every time.

Proposed resolution

Stop using UncacheableDependencyTrait in FacetsBlock and implement getCacheMaxAge(), getCacheTags() and getCacheContexts().

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France prudloff Lille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @prudloff
  • Merge request !10Issue #3354943: Make block cacheable → (Open) created by prudloff
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    2 pass
  • Status changed to Needs review almost 2 years ago
  • 🇪🇸Spain frouco

    This patch solved our issue, where authenticated users lost the pre-configured arguments on page reload

  • Pipeline finished with Success
    about 1 month ago
    Total: 153s
    #442751
  • 🇫🇷France prudloff Lille

    Merge latest 2.0.x so we can have CI tests in the MR.

  • Pipeline finished with Success
    about 1 month ago
    Total: 147s
    #442760
  • Pipeline finished with Success
    about 1 month ago
    Total: 157s
    #442763
  • 🇫🇷France arousseau

    \Drupal\block\BlockViewBuilder::viewMultiple collects cache metadata correctly after applying the MR

    Example without the patch:

    "contexts" => [
      0 => "languages:language_interface"
    ]
    "tags" => [
      0 => "block_view"
      1 => "config:block.block.front_facetsblock"
    ]
    

    With the patch:

    "contexts" => [
      0 => "languages:language_interface"
      1 => "languages:language_content"
      2 => "url.query_args"
      3 => "user.node_grants:view"
      4 => "facets_filter:f"
    ]
    "tags" => [
      0 => "block_view"
      1 => "config:block.block.front_facetsblock"
      2 => "config:facets.facet.test"
      3 => "config:search_api.index.test"
      4 => "search_api_list:test"
      5 => "config:views.view.test_facets_block"
    ]
    
Production build 0.71.5 2024