API page: https://api.drupal.org/api/drupal/core%21modules%21options%21options.mod...
As @dawehner_ pointed out that this cache_id is not good:)
<?php
$cache_id = implode(':', array($entity->entityType(), $entity->bundle(), $field_definition->getFieldName()));
?>
This cache_id doesn't involve with entity level, only entity type, bundle and field name. But in fact, this function's result could depend on parameter EntityInterface $entity potentially. See
<?php
$function = $field_definition->getFieldSetting('allowed_values_function');
// If $cacheable is FALSE, then the allowed values are not statically
// cached. See options_test_dynamic_values_callback() for an example of
// generating dynamic and uncached values.
$cacheable = TRUE;
if (!empty($function)) {
$values = $function($field_definition, $entity, $cacheable);
}
?>
It needs entity to return value, but the cache_id doesn't count the entity identifier, so the dynamic feature for each entity wouldn't fly.
While there's an issue #2012130: Regression: Views integration for "list" field types is broken about whether we need this feature, we need to adjust the cache_id to make this feature work correctly. It depends on field_definition, if this field makes use of
<?php
$function = $field_definition->getFieldSetting('allowed_values_function');
?>
we need to count the entity identifier, e.g., 'Uuid of this entity' into cache_id. Otherwise, it's ok to use current cache_id.