Cache issue persists after update to 8.x-2.0-alpha2

Created on 19 June 2020, almost 5 years ago
Updated 26 September 2024, 7 months ago

After updating to 8.x-2.0-alpha2, entities that contain fields that have been marked as uncacheable are still being cached.

The reason for this is the changes to the last installed definition don't happen until a field config is modified and the cacheability settings for an entity type change. Therefore we need an update script to ensure the last installed definition settings for existing entity types are set correctly.

Also, in addition to acting on field config changes, I believe we also need to ensure the correct cache settings are applied on entity type updates. If the maintainer of an entity type utilizes \Drupal\Core\Entity\EntityDefinitionUpdateManager::getEntityType() to load the entity type definition before updating then all should be good as the field encrypt overrides should persist. But if they don't, or they modify the cache properties then entities we don't want cached could be cached again.

I have added a patch to:

  • Add an Entity Type listener to act on entity type definition updates.
  • Introduce a EntityTypeCacheableManager service (for lack of a better name) to consolidate the entity type cache property related logic.
  • Refactored field_encrypt_entity_type_alter() to use the EntityTypeCacheableManager service
  • Refactored \Drupal\field_encrypt\EventSubscriber\ConfigSubscriber::setUncacheableEntityTypes() to use the EntityTypeCacheableManager service and only affect the entity type containing the field who's configuration was updated

Here is the code for the update method which will need to be added to the patch before it is committed:

/**
 * Update all uncacheable entity types.
 *
 * This will ensure the last installed definition of these entity types are
 * set correctly.
 *
 * @see \Drupal\field_encrypt\EventSubscriber\EntityTypeSubscriber::onEntityTypeUpdate()
 */
function field_encrypt_update_8201() {
  $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $uncacheable_types = \Drupal::state()->get(EntityTypeCacheableManager::UNCACHEABLE_TYPES_STATE_KEY);
  foreach ($entity_definition_update_manager->getEntityTypes() as $entity_type_id => $entity_type) {
    if (array_key_exists($entity_type_id, $uncacheable_types)) {
      $entity_definition_update_manager->updateEntityType($entity_type);
    }
  }

  return t("Entity Types have been updated to account for Field Encrypt uncacheable settings.");
}
🐛 Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

🇨🇦Canada tame4tex

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024