Cache services:
// cacheDefault is injected cache.default service.
$cid = 'module_name:route.name:' . $entity->id . ':' .
$entity->field_reference->entity->id;
if ($cache = $this->cacheDefault->get($cid) {
$data = $cache->data;
}
else {
$data = my_module_complicated_calculation();
// optional $expire and $tags parameters omitted for clarity.
$this->cacheDefault->set($cid, $data);
}
core.services.yml
for cache.bin
to see examples.
drupal site:mode dev
will get you most of the way.services.yml
set http.response.debug_cacheability_headers
to true
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
$render_array = (
'#cache => array(
'max-age' => 0,
'tags' => array(),
'contexts' => array(),
);
);
drupal generate:event:subscriber