Automatic filtering by cache contexts

Created on 5 February 2019, over 6 years ago
Updated 17 April 2025, about 2 months ago

Problem/Motivation

Blacklist parameter is a reactive way to ignore parameters sent by traffic sources (GA, Facebook, other social networks).
At the same time, Drupal has well working mechanism of determining what URL parameters are important for the request - it's response cache contexts.

I.e. if a page contains a view with exposed filters, each filter's machine name will be present in response cache contexts list as `url.query_args:`

Proposed resolution

- Add new configuration parameter 'filter_response_context', defaulting to FALSE
- When this parameter is set to TRUE, check if request contains parameters that are not expected by response, and ignore response in this case.

Remaining tasks

User interface changes

No UI changes

API changes

Internal method generateUrlOrPathToRegister() gets additional parameter $response

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇧🇬Bulgaria valthebald Sofia

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany webflo

    I'm going to try it out in a project.

  • 🇩🇪Germany webflo

    Fixed PHP error, url_to_store not initialized

  • 🇳🇿New Zealand ericgsmith

    I.e. if a page contains a view with exposed filters, each filter's machine name will be present in response cache contexts list as `url.query_args:`

    Are we sure this premise is true? I'm just trying this patch on an existing project and don't see this.

    I've got a view with exposed filters, which exposes a taxonomy term with the url query param "type". When I apply this patch and debug the cache contexts I see the more generic url.query_args context is present but nothing specific for type - there is no url.query_args:type. I don't know if that is optimized away at some point or if views isn't adding it - I have not debugged further. With the current patch its then leaves type in the $query_params and the returns NULL, incorrectly skipping this page from the registry.

    I need to test this on a clean install / check where cache contexts get optimized as query param garbage is a huge problem for me too / this module and am super interested in solutions to this problem.

  • 🇳🇿New Zealand ericgsmith

    On further investigation - I don't think views is smart enough to add all the specific contexts as the issue summary describes, I can only see it adding the full url context here https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/views...

Production build 0.71.5 2024