I tried setting the cache max-age to 0 in hook_views_pre_view
, in hook_views_pre_build
and in hook_views_query_alter
but it just doesn't work.
Eg:
function my_module_views_pre_build(ViewExecutable $view) {
$view->element['#cache']['max-age'] = 0;
}
The views caches the response until the caches are cleared.
I need to do this programatically because I need to force the views to not cache the results for more than 10 minutes based on some conditions.
Later Edit: The issue discussed in "How to use max-age" does not apply in my case. I know how to use cache tags, contexts and max-age for pages/rendered arrays and they work just fine. But for views I can't make them work.