I have a custom page displaying a query result from the database. Before I attempt to cache it myself, I am trying to see if Drupal 8 render arrays support caching in anyway for authenticated users. My use case is a route and a controller on the node entity. Users go to node/id/something that displays a list of entries in a table. I would like to cache this in the controller.
I am using the following code.
public function displayContent(NodeInterface $node) {
// query the DB to generate content.
$content['#markup'] = $result_of_db_query;
$content['#cache'] = [
'keys' => ['entity_view', 'node', $node->id()],
'tags' => ['node:' . $node->id()],
'max-age' => Cache::PERMANENT,
];
return $content;
}
It doesn't work: The database query is executed on every page request. I am not sure if this is due to the fact this page is an administrative page and users must be authenticated.