Here's a simple "Hello World" controller. It's working correctly, except for the "max-age" statement. The request returns a Drupal cache hit every time after the first request, rather than just for 5 seconds. I've tried to find a simple example of how to do this but haven't had much luck. If anyone could help, that would be very much appreciated.
<?php
/**
* @file
* Contains \Drupal\hello_world\Controller\HelloController.
*/
namespace Drupal\hello_world\Controller;
use Drupal\Core\Controller\ControllerBase;
class HelloController extends ControllerBase {
public function content() {
return array(
'#type' => 'markup',
'#markup' => $this->t('Hello, World!'),
// THIS ISN'T WORKING:
'#cache' => array("max-age" => 5),
);
}
}
?>