'#cache' => [
'contexts' => ['languages', 'timezone', 'user'],
'tags' => ['node:5', 'user:6'],
'max-age' => Cache::PERMANENT,
],Cache max-age = time dependencies
Cache max-age is analogous to HTTP's Cache-Control header's max-age directive
# Example for most render arrays:
$build['#cache']['max-age'] = 0;
# Example in a function:
\Drupal::cache()->set('my_cache_item', $school_list, REQUEST_TIME + (86400));Cache contexts = (request) context dependencies
Cache contexts are analogous to HTTP's Vary header.
Cache tags = data dependencies
Cache tags describe dependencies on data managed by Drupal
# Set
$cache_backend->set(
$cid, $data, Cache::PERMANENT, ['node:5', 'user:7']
);
# Invalidate
cache_tags.invalidator:invalidateTags()$build[$id]['links'] = array(
'#lazy_builder' => [
'comment.lazy_builders:renderLinks',
[
$entity->id(),
$view_mode,
$entity->language()->getId(),
!empty($entity->in_preview),
],
],
'#create_placeholder' => TRUE,
);