Random selection on every page load

Created on 23 July 2025, 14 days ago

I’ve got a multi-value media field that I’m using to show some images. We’re using the field_formatter_range’s ‘random’ display option to show 6 random images from the field.

What the client would like to see is a new set of 6 images every time they refresh the page. What we’re seeing is the same 6 images in the same order until we re-save the node or clear caches. Then we get a new set of images.

I’ve disabled caches at every level I know how to for troubleshooting, but the result is the same: we get the same images everywhere — across all devices and browsers — until cache is cleared or node is re-saved.

Any direction would be greatly appreciated!

💬 Support request
Status

Active

Version

1.6

Component

Code

Created by

🇨🇦Canada mrogers

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mrogers
  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    Try this in your settings.php:

      $settings['container_yamls'][] = $app_root . '/sites/development.services.yml';
      $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
      $settings['cache']['bins']['page'] = 'cache.backend.null';
      $settings['cache']['bins']['render'] = 'cache.backend.null';
    

    The problem is that preventing the usage of cache and having that re-computed at each page refresh is a performance killer.

    In this case an opt-in should be provided to allow to explicitly choose that you want to disable the render cache for this field.

Production build 0.71.5 2024