How do I disable cache in my entityQuery? 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(&amp;$variables)
{
    $nids = \Drupal::entityQuery('node')
        -&gt;condition('type', 'recipe')
        -&gt;condition('status', 1)
        -&gt;addTag('sort_by_random')
        -&gt;range(0, 3)
        -&gt;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.
You'll need to make this an un-cachable block and place it on your template file, otherwise, you would have to turn off page caching. 

But unless this is the only thing on that page, and there isn't something else in here worth caching, then you could alternately turn off caching for this specific page(s).