Dynamic cache does not respect query parameters

Created on 10 May 2017, over 7 years ago
Updated 14 June 2023, over 1 year ago

Problem/Motivation

We have a Drupal Commerce checkout using an off-site iframe for payment. It pings a callback controller and with some other logic we load a route using a ?refid= query parameter. Despite this value changing, or being present and then not, the page is HIT after first view by dynamic page cache

Data from Chrome dev tools network tab:

First request:

Request URL:https://example.com/checkout/zuora/2804/payment?refid=
Request Method:GET
Status Code:302 

cache-control:must-revalidate, no-cache, private
content-language:en
content-type:text/html; charset=UTF-8
date:Wed, 10 May 2017 21:32:35 GMT
expires:Sun, 19 Nov 1978 05:00:00 GMT
location:/checkout/2804/payment
server:nginx
status:302
x-drupal-dynamic-cache:MISS

Second request

Request URL:https://example.com/checkout/zuora/2804/payment?refid=REDACTED_VALUE
Request Method:GET
Status Code:302 

cache-control:must-revalidate, no-cache, private
content-language:en
content-type:text/html; charset=UTF-8
date:Wed, 10 May 2017 21:32:35 GMT
expires:Sun, 19 Nov 1978 05:00:00 GMT
location:/checkout/2804/payment
server:nginx
status:302
x-drupal-dynamic-cache:HIT

Since the refid was present, it should have had a different location header.

For now, I have disabled cache on this route. But I had to move this callback out of our checkout plugin and into a custom route with caches disabled.

Proposed resolution

No idea. \Drupal\Core\Cache\Context\RouteCacheContext checks the route parameters. Which is what the $dynamicPageCacheRedirectRenderArray uses. It also checks request format.

Maybe also add url.query_args as render context?

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Closed: works as designed

Version

8.4 ⚰️

Component
Dynamic page cacheΒ  β†’

Last updated about 2 months ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

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.

  • πŸ‡«πŸ‡·France floriane

    I had this problem with my controller's module, which took the cache value instead of the url one (i'm using Drupal 10)

    I solved the problem with #cache and max-age to 0:

            $address = $request->query->get('adresse');
    
            return [
                '#address' => $address,
                '#cache' => [
                    'max-age' => 0,
                ],
            ];
    
Production build 0.71.5 2024