Bypassing internal cache via query parameter I'm attempting to bypass drupal's internal page cache and dynamic cache when a given url parameter is in a URL (as an anonymous user). The page in question is a view, and occasionally, when a user clicks a link to load that view, the URL has the associated query param. I've tried a number of different ways to add the cache context like below:

$vars['#cache']['contexts'][] = 'url.query_args:dynamic_trials';

I've added this in a hook_preprocess_node, I've added it in a preprocess on the view itself I've added it in a function tibco_views_utils_views_pre_view with a call to 

view-&gt;element['#cache']['contexts'][] = 'url.query_args:dynamic_trials';

None of these have worked. I noticed this on one of the drupal docs pages:

Note the Internal Page Cache assumes that all pages served to anonymous users will be identical, regardless of the implementation of cache contexts. If you want to use cache contexts to vary the content served to anonymous users, this module must be disabled, and the performance impact that entails incurred

Is this true? There's no way to do what I'm trying to do above without disabling the internal page cache entirely?
The Internal Page Cache is designed to serve database content requested by a URL (the entire URL including query string). It works as long as you don't have any dynamic component, for example time based, or client request data not included in URL or session cookie, like request headers or custom cookies.

The Dynamic Page cache works on a different level. It doesn't depend on the URL directly but on the matched route. Any code using contextual data from the request or the matched route has to declare these dependencies as cache metadata.

Your problem is custom code in a Views hook. The old style Views hooks have a very narrow scope while at the same time you can access the entire View. So not all code snippets you find are good practice. Better use the Views plugin system for custom code.

For the caching part the easiest way would be to use the code of the Views caching plugins already in core which you control through the advanced settings of the View. If you only have anonymous traffic already cached by the Internal Page Cache you could disable caching of the View without impacting performance. Either through the none caching plugin or the time-based plugin which gives you finer control.