I created a preprocess function in my recipe node page, inside that function I want to get 3 random recipes everytime the user accessess the page.
I have this code:
function sometheme_preprocess_node__recipe__full(&$variables)
{
$nids = \Drupal::entityQuery('node')
->condition('type', 'recipe')
->condition('status', 1)
->addTag('sort_by_random')
->range(0, 3)
->execute();
$variables['random_recipes'] = \Drupal\node\Entity\Node::loadMultiple($nids);
}
But I notice that the recipes doesn't random because of Drupal cache system.
I don't want to turn off the overall cache system of Drupal for perfomance purposes.
I just want to disable cache programmatically when I get the random recipes.