I have a module that defines route /x and assigns it the controller ViewNodes::show. This takes no parameters and the show method simply returns a nearly blank render array:
[ '#theme' => 'view_nodes', '#cache' => ['tags' => ['node_list'], 'max-age' => Cache::PERMANENT, 'bin' => 'render'], '#pre_render' => [[$this, 'buildNodeListView']] ];
The buildNodeListView then takes care of doing all the expensive logic and SQL queries to build the array. This all works fine and the page displays as expected, but devel's WebProfiler shows the SQL queries for building the render array are still being executed even when they should have been cached. This suggests buildNodeListView is always being called, which means #pre_render is always being called, which means the render array is always a miss. Am I mistaken here?
The route shows up under "bin dynamic_page_cache" and is always marked as MISS. And in the HTTP headers, there's always X-DRUPAL-DYNAMIC-CACHE: UNCACHEABLE
Is there something I'm doing wrong, or things I should check to further debug this? My settings.local.php has
//$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
//$settings['cache']['bins']['render'] = 'cache.backend.null';
They're both commented out so the caching should be enabled. The Dynamic Page Cache module is also enabled. And my routes do not have the "no_cache" option.